Versions Compared

Key

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

...

Code Block
xml
xml
    <bean id="myRedeliveryPolicy" class="org.apache.camel.processor.RedeliveryPolicy">
        <property name="maximumRedeliveries" value="${myprop.max}"/>
    </bean>

     <onException>
         <!-- you can define multiple exceptions just adding more exception elements as show below -->
         <exception>com.mycompany.MyFirstException</exception>
         <exception>com.mycompany.MySecondException</exception>

         <!-- here we reference our redelivery policy defined above -->
         <redeliveryPolicy ref="myRedeliveryPolicy"/>
     </onException>

Delayed redelivery

From Camel 2.4 onwards Camel will not block while waiting for a delayed redelivery to occur (its asynchronous). However if you use transacted routes then Camel will block as its mandated by the transaction manager to execute all the work in the same thread context. You can disable the non blocking behavior by the syncDelayedRedelivery option, which instructs Camel to always block while waiting. This occurs synchronously in the same thread.

Since Camel by default is asynchronous for delayed redelivery it could occur that a message is to be redelivered, and while it waits, the route could pickup a new message and have it routed successfully. This can cause out of order of messaging, as the redelivered message will then be completed after that 2nd message.

Catching multiple exceptions

...

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

Using fine grained retry using

...

retryWhile predicate

Available as of Camel 2.0

Info
RetryUntil
RetryUntil

In Camel 2.0 to 2.3 its called retryUntil. From Camel 2.4 onwards its named retryWhile because Camel will continue doing retries while the predicate returns true.

When you need fine grained control for determining if an exchange should be retried or not you can use the retryUntil retryWhile predicate. Camel will redeliver until the predicate returns false.
This is demonstrated in the sample below:

...