Error Handling


Summary: Configuration of IM error handling — retry policies, exponential backoff, error email notifications, and error message aggregation.


Configuration

Default Error Handler Properties

To change the behavior of the default error handler, put the following properties into application.properties.

Property

Since

Default

Description

integration.route-error-handling.enabled


true

Whether the defaultErrorHandler bean should be created

integration.route-error-handling.maximumRedeliveries


10

Maximum redelivery attempts. Negative value = retry forever

integration.route-error-handling.redeliveryDelay


2000

Initial redelivery delay in milliseconds

integration.route-error-handling.maximumRedeliveryDelay


300000

Maximum redelivery delay in ms. Use -1 for no maximum

integration.route-error-handling.useExponentialBackOff


true

Enable exponential backoff using backOffMultiplier

integration.route-error-handling.backOffMultiplier


2.0

Multiplier for delay between redeliveries

integration.route-error-handling.logHandled


true

Log errors even if handled

integration.route-error-handling.retryAttemptedLogLevel


INFO

Log level for retry attempts (TRACE, DEBUG, INFO, WARN, ERROR, OFF)

integration.route-error-handling.logRetryAttempted


true

Whether to log retry attempts

integration.route-error-handling.logStackTrace


true

Whether to log stack traces

Retryable Exceptions and HTTP Status Codes

Property

Since

Default

Description

integration.route-error-handling.retry.exceptions

1.1.17

RecoverableException, ConnectTimeoutException, ConnectException

Comma-separated FQCNs of exceptions to retry

integration.route-error-handling.retry.httpStatus

1.1.17

409, 503, 504

Comma-separated HTTP status codes to retry

integration.route-error-handling.retry.overrideDefaults

1.1.17

false

If true, configured values replace defaults. If false, they are appended

Email Notification Properties

Property

Since

Default

Description

integration.route-error-handling.enable-sending-mail

1.1.18

false

Enable error email notifications

integration.route-error-handling.email.smtpHost


localhost

SMTP hostname

integration.route-error-handling.email.smtPort


25

SMTP port

integration.route-error-handling.email.smtpAuth


false

Enable SMTP authentication

integration.route-error-handling.email.smtpAuthUsername



SMTP auth username

integration.route-error-handling.email.smtpAuthPassword



SMTP auth password

integration.route-error-handling.email.smtp-ssl


false

Enable SSL for SMTP

integration.route-error-handling.email.smtpSslProtocols

4.10.10, 5.4.0


SSL protocols for SMTP (whitespace-separated)

integration.route-error-handling.email.mailFrom


integration@pricefx.eu

Email sender address

integration.route-error-handling.email.mailTo


integration@pricefx.eu

Email recipients (semicolon-separated)

integration.route-error-handling.email.mailSubject


Camel processing error!

Email subject

integration.route-error-handling.email.emailContentTemplate

1.1.18

email/default-email-template.vm

Velocity template for error email body

Error Message Aggregation

Property

Since

Default

Description

integration.route-error-handling.email.aggregation.enabled

1.9.0

false

Enable error message aggregation

integration.route-error-handling.email.aggregation.checkPeriodInSeconds

1.9.0

600

Check period for aggregation (seconds)

integration.route-error-handling.email.aggregation.aggregateErrorSize

1.9.0

0

Error message size for aggregation key. 0 = first line

integration.route-error-handling.email.aggregation.similarityErrors

1.9.0

1.0

Error similarity threshold (0.0-1.0). 1.0 = exact match

integration.route-error-handling.email.aggregation.mailSubject

1.9.0

${integration.name} Summary integration processing report!

Summary email subject

integration.route-error-handling.email.aggregation.differentErrorTypes

1.9.0

10

Max different error types stored in memory

Applying Error Handler to Camel Context

Use the defaultErrorHandler bean reference as the Camel context attribute:

XML
<camelContext xmlns="http://camel.apache.org/schema/spring" useMDCLogging="true" errorHandlerRef="defaultErrorHandler">

Custom Error Email Template

  1. Create a Velocity template:

Hello error template of exchange ${exchange.exchangeId}

with body ${body}

and headers ${headers}

caused by ${exchange.properties.CamelExceptionCaught}
  1. Configure:

integration.route-error-handling.enable-sending-mail=true
integration.route-error-handling.email.emailContentTemplate=file:///path/to/my-template.vm

Convention for Email Configuration

  • PROD partitions: mailTo=<IE email>;integration@pricefx.eu

  • QA/DEV partitions: mailTo=<IE email>

  • mailFrom convention: integration_<pfx.partition>@pricefx.eu


Understanding Retry Behavior

Which Errors Are Retried?

By default, IM retries these exception types:

  • RecoverableException — transient Pricefx API errors

  • ConnectTimeoutException — network timeout connecting to host

  • ConnectException — connection refused

And these HTTP status codes:

  • 409 — Conflict (concurrent load/flush in progress)

  • 503 — Service Unavailable (server temporarily down)

  • 504 — Gateway Timeout

All other errors are not retried and fail immediately. To add custom retryable exceptions or status codes, use the retry.exceptions and retry.httpStatus properties.

Retry Timeline Example

With default settings (10 retries, 2s initial delay, 2.0 multiplier, 300s max):

Attempt

Delay

Cumulative

1

2s

2s

2

4s

6s

3

8s

14s

4

16s

30s

5

32s

62s

6

64s

~2 min

7

128s

~4 min

8

256s

~8 min

9

300s (max)

~13 min

10

300s (max)

~18 min

After all retries are exhausted, the error handler either sends an email (if enabled) or the route fails.

Retry vs. Fail Fast

Scenario

Recommendation

ConnectTimeoutException

Retry — transient network issue

HTTP 409 Conflict

Retry — another operation in progress

HTTP 503 Service Unavailable

Retry — server restarting

HTTP 400 Bad Request

Do not retry — fix the request

HTTP 401 Unauthorized

Do not retry — fix credentials

HTTP 404 Not Found

Do not retry — fix the target

IllegalStateException

Do not retry — fix configuration

CSV parse error

Do not retry — fix the source data


Route-Level Error Handling

onCompletion for Cleanup

Use onCompletion to run cleanup logic regardless of success or failure:

XML
<route id="import-with-cleanup">
    <from uri="file:..."/>
    <to uri="pfx-api:loaddata?objectType=P&amp;mapper=myMapper"/>

    <!-- Only on success -->
    <onCompletion onCompleteOnly="true">
        <log message="Import succeeded"/>
    </onCompletion>

    <!-- Only on failure -->
    <onCompletion onFailureOnly="true">
        <log message="Import failed: ${exception.message}" loggingLevel="ERROR"/>
    </onCompletion>
</route>

doTry / doCatch for Specific Error Handling

XML
<route id="import-with-catch">
    <from uri="file:..."/>
    <doTry>
        <to uri="pfx-api:loaddata?objectType=P&amp;mapper=myMapper"/>
        <doCatch>
            <exception>java.net.ConnectException</exception>
            <log message="Connection failed, will retry later" loggingLevel="WARN"/>
            <!-- Move file back for reprocessing -->
        </doCatch>
        <doCatch>
            <exception>java.lang.IllegalStateException</exception>
            <log message="Configuration error: ${exception.message}" loggingLevel="ERROR"/>
            <!-- Move file to error folder -->
        </doCatch>
    </doTry>
</route>

See Also

  • Troubleshooting — common runtime errors and solutions

  • Debugging — debug logging and exchange inspection

  • Properties — all integration.route-error-handling.* properties


TLS Example

Properties setup:

integration.route-error-handling.enabled=true
integration.route-error-handling.maximumRedeliveries=3
integration.route-error-handling.enableSendingMail=true
integration.route-error-handling.email.mailTo=michal.stepan@pricefx.com
integration.route-error-handling.email.smtpHost=mail.pricefx.eu
integration.route-error-handling.email.smtpPort=587
integration.route-error-handling.email.smtpAuth=true
integration.route-error-handling.email.smtpAuthUsername=xxx
integration.route-error-handling.email.smtpAuthPassword=xxx
integration.route-error-handling.email.smtpTls=true

Route:

XML
        <route >
            <from uri="timer:foo?repeatCount=1"/>
            <throwException message="Olala" exceptionType="java.lang.RuntimeException"/>
            <log message="Finito"/>
        </route>

Route contains failure and throws exception. The processing is retried 3 times. If the processing is still not successful, email is sent via mail.pricefx.eu TLS:

Snímek obrazovky 2022-01-13 v 15.52.51-20220113-145300.png