Versions Compared

Key

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

...

OnRedelivery

Available in Camel 1.56.1 0 onwards

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. See below for sample.

...

How can I modify the Exchange before redelivery?

In Camel 1.56.1 0 we added support directly in Dead Letter Channel to set a Processor that is executed before each redelivery attempt. In older releases you have to sort to other solutions that isn't as solid as this new feature.

Camel 1.5.0 or older

When Dead Letter Channel is doing redeliver it redeliveries immediately with the original Exchange that caused the error in the first place. However in some situations you might want to be able to alter the message before its redelivered. As Camel at this time of writing doesn't have a nice DSL syntax or configuration on the Dead Letter Channel to allow custom processing before redeliver we are gonna show a different solution, that actually also pin points the flexibility Camel has.

We are going to use an interceptor that gets triggered when an Exchange is being redelivered. We use the fact that interceptors by default will proceed from the point of interceptor. This is the Detour EIP pattern we are using.

The code below demonstrates this.

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/InterceptAlterMessageBeforeRedeliveryTest.java}
Info
titleCode uses wrong header key

As the code above is based on an unit test its based on Camel 2.x or newer. The header to use in Camel 1.x should be "org.apache.camel.redeliveryCount" instead of "CamelRedeliveryCount".

However you should notice as Camel will keep the redeliver flag on the Exchange for the remainder of its routing this interceptor will kick in for subsequence processing. So you should keep track if you already have altered the message before redelivery.

...

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.

...