Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Tip
titleDifference between Dead Letter Channel and Default Error Handler

The major difference is that Dead Letter Channel has a dead letter queue that whenever an Exchange could not be processed is moved to. It will always move failed exchanges to this queue.Unlike the Default Error Handler that does not have a dead letter queue. So whenever an Exchange could not be processed the error is propagated back to the client.does very little: it ends the Exchange immediately and propagates the thrown Exception back to the caller.

The Dead Letter Channel lets you control behaviors including redelivery, whether to propagate the thrown Exception to the caller (the handled option), and where the (failed) Exchange should now be routed toNotice: You can adjust this behavior of whether the client should be notified or not with the handled option.

When the DeadLetterChannel moves a message to the dead letter endpoint, then if any new exceptions is thrown during that process, then Exception thrown is by default handled by the dead letter channel will handle the new exception as well. This ensures that the DeadLetterChannel will always succeed. From Camel 2.15 onwards this behavior can be changed by setting the option deadLetterHandleNewException=false. Then if a new exception Exception is thrown, then the dead letter channel will fail and propagate back that new exception Exception (which is the behavior of the default error handler). When a new exception Exception occurs then the dead letter channel logs this at WARN level. This can be turned off by setting logNewException=false.

...

Prior to Camel 2.10, Camel will perform redelivery while stopping a route, or shutting down Camel. This has improved a bit in Camel 2.10 onwards, as Camel will not perform redelivery attempts when shutting down aggressively (eg during Graceful Shutdown and timeout hit). From Camel 2.11 onwards there is a new option allowRedeliveryWhileStopping which you can use to control if redelivery is allowed or not; notice that any in progress redelivery will still be executed. This option can only disallow any redelivery to be executed after the stopping of a route/shutdown of Camel has been triggered. If a redelivery is dissallowed then a RejectedExcutionException is set on the Exchange and the processing of the Exchange stops. This means any consumer will see the Exchange as failed due the RejectedExecutionException.see the Exchange as failed due the RejectedExecutionException.

The default value is true to be backwards compatible as before. For example the following sample shows how to do this with Java DSL and XML DSL

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliveryErrorHandlerNoRedeliveryOnShutdownTest.java}

And the sample sample with XML DSL

Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.xml}

Samples

The following example shows how to configure the Dead Letter Channel configuration using the The default value is true to be backwards compatible as before. For example the following sample shows how to do this with Java DSL and XML DSL

Wiki Markup
{snippet:id=e1e3|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processorbuilder/RedeliveryErrorHandlerNoRedeliveryOnShutdownTestErrorHandlerTest.java}

And the sample sample with XML DSLYou can also configure the RedeliveryPolicy as this example shows

Wiki Markup
{snippet:id=e1e4|lang=xmljava|url=camel/trunk/components/camel-springcore/src/test/resourcesjava/org/apache/camel/spring/processor/SpringRedeliveryErrorHandlerNoRedeliveryOnShutdownTest.xml}

Samples

builder/ErrorHandlerTest.java}

How can I modify the Exchange before redelivery?

We support directly in Dead Letter Channel to set a Processor that is executed before each redelivery attempt.

When Dead Letter Channel is doing redeliver its possible to configure a Processor that is executed just before every redelivery attempt. This can be used for the situations where you need to alter the message before its redelivered.

Here we configure the Dead Letter Channel to use our processor MyRedeliveryProcessor to be executed before each redelivery.The following example shows how to configure the Dead Letter Channel configuration using the DSL

Wiki Markup
{snippet:id=e3e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/builderprocessor/ErrorHandlerTestDeadLetterChannelOnRedeliveryTest.java}

You can also configure the RedeliveryPolicy as this example showsAnd this is the processor MyRedeliveryProcessor where we alter the message.

Wiki Markup
{snippet:id=e4e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/builderprocessor/ErrorHandlerTestDeadLetterChannelOnRedeliveryTest.java}

How can I

...

log what caused the Dead Letter Channel

...

When Dead Letter Channel is doing redeliver its possible to configure a Processor that is executed just before every redelivery attempt. This can be used for the situations where you need to alter the message before its redelivered.

Here we configure the Dead Letter Channel to use our processor MyRedeliveryProcessor to be executed before each redelivery.

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelOnRedeliveryTest.java}

And this is the processor MyRedeliveryProcessor where we alter the message.

...

to be invoked?

You often need to know what went wrong that caused the Dead Letter Channel to be used and it does not offer logging for this purpose. So the Dead Letter Channel's endpoint can be set to a endpoint of our own (such as direct:deadLetterChannel). We write a route to accept this Exchange and log the Exception, then forward on to where we want the failed Exchange moved to (which might be a DLQ queue for instance). See also http://stackoverflow.com/questions/13711462/logging-camel-exceptions-and-sending-to-the-dead-letter-channel

...

Include Page
Using This Pattern
Using This Pattern

...