RedeliveryPolicy in Apache Camel defines how Camel retries an exchange after a failure: how many times, how long to wait between attempts, whether the delay grows, and what to log. It is the retry configuration used by Camel's error handlers, namely the default error handler, the dead letter channel and onException clauses. With a sensible policy, transient failures such as a brief network error recover without losing the message.
You rarely instantiate the class yourself. In the Java DSL you set its options through methods like maximumRedeliveries() and redeliveryDelay() on onException, errorHandler or deadLetterChannel.
RedeliveryPolicy fits in Camel error handlingRedeliveryPolicy fits in Camel error handlingCamel runs every route under an error handler. When a processor throws, the error handler consults its redelivery policy to decide whether to try again. The class is org.apache.camel.processor.errorhandler.RedeliveryPolicy in Camel 3.x and 4.x.
Defaults matter. With the default error handler Camel does not redeliver at all: maximumRedeliveries is 0, so the exception propagates to the caller immediately. The default redeliveryDelay is 1000 milliseconds, which only applies once you enable retries. Redelivery is therefore opt-in.
Camel 4 requires Java 17 or newer, and the examples here use the Java DSL.
| Option | Meaning |
|---|---|
maximumRedeliveries | Number of retries after the first failure. -1 means retry forever, 0 disables retries |
redeliveryDelay | Wait in milliseconds before each retry |
useExponentialBackOff | Multiply the delay after each attempt |
backOffMultiplier | Multiplier used for exponential backoff, for example 2.0 |
maximumRedeliveryDelay | Upper bound for the delay when backoff is on |
useCollisionAvoidance and collisionAvoidanceFactor | Add random jitter so many failing exchanges do not retry at the same moment |
retryAttemptedLogLevel and logRetryAttempted | How redelivery attempts are logged |
logStackTrace, logExhausted, logHandled | Control logging of failures |
retriesExhaustedLogLevel | Level used when all retries are used up |
Retry for ever with -1 only when something else bounds the work, because a poison message then blocks the route.
onException applies a policy only to the exception types you list, which is the usual way to retry transient errors without retrying programming errors.
The route retries an IOException up to four times, with waits of roughly 500 ms, 1 s, 2 s and 4 s, and logs each attempt at WARN. An IllegalArgumentException is not retried, because bad input will fail again, and the route sends it to direct:invalid and treats it as handled.
A dead letter channel redelivers and then moves the message to another endpoint when retries run out.
useOriginalMessage() sends the message as it first entered the route, not the half-transformed copy at the point of failure, which makes replay safe. A dead letter channel handles the exception by default, so the original consumer is not told about the failure.
In a Camel Spring Boot application, you can declare a shared error handler bean and reference it by name.
Routes that use errorHandler(...) apply the setup to every route in the same RouteBuilder.
No. With the default error handler maximumRedeliveries is 0, so the first failure is final unless you configure a policy.
Camel redelivery retries the failed part of the route inside Camel. A transacted route can instead roll back the message to the broker, which then redelivers it according to its own settings.
Set maximumRedeliveries(-1). Combine it with a capped delay and a way to stop the route, because one failing message can block all later ones.
The retry restarts from the processor that failed, within the scope of the error handler, so earlier steps in the route are not repeated unless the failure occurs before them.
RedeliveryPolicy is Camel's retry setting for failed exchanges. It controls the retry count, delay, exponential backoff, jitter and logging. Redelivery is off by default, so enable it with onException or a dead letter channel, retry only transient exceptions, make processors idempotent, and send exhausted messages to a dead letter queue.