RedeliveryPolicy

A redelivery policy defines rules when Camel Error Handler perform redelivery attempts. For example you can setup rules that state how many times to try redelivery, and the delay in between attempts, and so forth.

You can use redelivery policies at two places in Camel:

For example you can define a default error handler to redelivery at most 3 times

errorHandler(defaultErrorHandler().maximumRedeliveries(3));

And in XML

<errorHandler id="defaultEH">
  <redeliveryPolicy maximumRedeliveries="3"/>
</errorHandler>

See more details at Error Handler.

The Camel Error Handler is covered in great details in the Camel in Action book where the entire chapter 5 has been devoted.

Using RedeliveryPolicyProfiles

Available as of Camel 2.7

In the XML snippet below we have defined a <redeliveryPolicyProfile> which we can refer to from the <errorHandler>.

<camelContext xmlns="http://camel.apache.org/schema/spring">

    <!-- define the default error handler, and refer to a redelivery policy to use -->
    <errorHandler id="eh" redeliveryPolicyRef="myPolicy"/>

    <!-- and the redelivery policy is a profile where we can configure it -->
    <redeliveryPolicyProfile id="myPolicy" maximumRedeliveries="3" redeliveryDelay="25" retryAttemptedLogLevel="WARN"/>

    <route errorHandlerRef="eh">
        <from uri="direct:start"/>
        <throwException ref="damn"/>
    </route>

</camelContext>

Camel's Properties placeholder is also supported which the following XML example shows:

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <!-- use Camel property placeholders -->
    <propertyPlaceholder id="properties" location="org/apache/camel/component/properties/cheese.properties"/>

    <!-- setup endpoint -->
    <endpoint id="dead" uri="mock:dead"/>

    <!-- setup a common redelivery policy, using property placeholders -->
    <redeliveryPolicyProfile id="myRedelivery" redeliveryDelay="{{delay}}" maximumRedeliveries="{{max}}"/>

    <route>
        <from uri="direct:start"/>
        <onException redeliveryPolicyRef="myRedelivery">
            <!-- refer to common redelivery policy -->
            <exception>java.lang.Exception</exception>
            <!-- but we can override the profile and log retry attempts at WARN level -->
            <redeliveryPolicy logRetryAttempted="true" retryAttemptedLogLevel="WARN"/>
            <to ref="dead"/>
        </onException>
        <throwException ref="damn"/>
    </route>

</camelContext>

And you can also use Spring Frameworks property placeholders as shown below:

<!-- use Spring property placeholder -->
<context:property-placeholder location="org/apache/camel/component/properties/cheese.properties"/>

<camelContext xmlns="http://camel.apache.org/schema/spring">

    <!-- setup endpoint -->
    <endpoint id="dead" uri="mock:dead"/>

    <!-- setup a common redelivery policy, using Spring property placeholders -->
    <redeliveryPolicyProfile id="myRedelivery" redeliveryDelay="${delay}" maximumRedeliveries="${max}"/>

    <route>
        <from uri="direct:start"/>
        <onException redeliveryPolicyRef="myRedelivery">
            <!-- refer to common redelivery policy -->
            <exception>java.lang.Exception</exception>
            <!-- but we can override the profile and log retry attempts at WARN level -->
            <redeliveryPolicy logRetryAttempted="true" retryAttemptedLogLevel="WARN"/>
            <to ref="dead"/>
        </onException>
        <throwException ref="damn"/>
    </route>

</camelContext>

See Also

© 2004-2011 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram