|
Page Edited :
CAMEL :
Dead Letter Channel
Dead Letter Channel has been edited by Jonathan Anstey (Nov 07, 2008). Content:Dead Letter ChannelCamel supports the Dead Letter Channel RedeliveryIt is common for a temporary outage or database deadlock to cause a message to fail to process; but the chances are if its tried a few more times with some time delay then it will complete fine. So we typically wish to use some kind of redelivery policy to decide how many times to try redeliver a message and how long to wait before redelivery attempts. The RedeliveryPolicy
Once all attempts at redelivering the message fails then the message is forwarded to the dead letter queue. Redelivery default valuesThe default redeliver policy will use the following values:
The maximum redeliver delay ensures that a delay is never longer than the value, default 1 minute. This can happen if you turn on the exponential backoff. The maximum redeliveries is the number of re delivery attempts. By default Camel will try to process the exchange 1 + 5 times. 1 time for the normal attempt and then 5 attempts as redeliveries. Camel will log delivery failures at the ERROR logging level by default. You can change this by specifying retriesExhaustedLogLevel and/or retryAttemptedLogLevel. See ExceptionBuilderWithRetryLoggingLevelSetTest Redelivery headerWhen a message is redelivered the DeadLetterChannel Configuring via the DSLThe following example shows how to configure the Dead Letter Channel configuration using the DSL RouteBuilder builder = new RouteBuilder() { public void configure() { errorHandler(deadLetterChannel("seda:errors")); from("seda:a").to("seda:b"); } };
The example below illustrates a common exception handling configuration in Camel: onException(NullPointerException.class)
.maximumRedeliveries(0)
.setHeader(MESSAGE_INFO, constant("Damm a NPE"))
.to(ERROR_QUEUE);
onException(IOException.class)
.delay(5000L)
.maximumRedeliveries(3)
.maximumRedeliveryDelay(30000L)
.backOffMultiplier(1.0)
.useExponentialBackOff()
.setHeader(MESSAGE_INFO, constant("Damm somekind of IO exception"))
.to(ERROR_QUEUE);
onException(Exception.class)
.delay(1000L)
.maximumRedeliveries(2)
.setHeader(MESSAGE_INFO, constant("Damm just exception"))
.to(ERROR_QUEUE);
onException(MyBaseBusinessException.class)
.delay(1000L)
.maximumRedeliveries(3)
.setHeader(MESSAGE_INFO, constant("Damm my business is not going to well"))
.to(BUSINESS_ERROR_QUEUE);
onException(GeneralSecurityException.class).onException(KeyException.class)
.maximumRedeliveries(1)
.setHeader(MESSAGE_INFO, constant("Damm some security error"))
.to(SECURITY_ERROR_QUEUE);
onException(InstantiationException.class, IllegalAccessException.class, ClassNotFoundException.class)
.maximumRedeliveries(0)
.setHeader(MESSAGE_INFO, constant("Damm some access error"))
.to(ERROR_QUEUE);
Here we have configured the handling of exceptions into three categories:
Camel will with the default strategy try to select the best suited category from above for any thrown exception. Camel supports pluggable exception policy strategies. See Error Handler for such details. Using This PatternIf you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out. |
Unsubscribe or edit your notifications preferences
