...
However if you want to customize any methods on the RedeliveryPolicy object, you can do this via the fluent API. So lets retry in case of org.apache.camel.ValidationException
up till two times.
Java DSL:
Code Block |
---|
|
onException(ValidationException.class)
.maximumRedeliveries(2);
|
And the spring Spring XML DSL:
Code Block |
---|
|
<onException>
<exception>com.mycompany.ValidationException</exception>
<redeliveryPolicy maximumRedeliveries="2"/>
</onException>
|
You can customize any of the RedeliveryPolicy so we can for instance set a different delay of 5000
millis:
Code Block |
---|
|
<onException>
<exception>com.mycompany.ValidationException</exception>
<redeliveryPolicy maximumRedeliveries="2" delay="5000"/>
</onException>
|
...
All redelivery attempts start at the point of the failure. So the route:
Code Block |
---|
|
.onException(ConnectException.class)
.from("direct:start")
.process("processor1")
.process("processor2") // <--- throws a ConnectException
.to("mock:theEnd")
|
...
Available as of Camel 1.5.1 or later
You can reference a RedeliveryPolicy
so you can reuse existing configurations and use standard spring bean style configuration that supports property placeholders.
Code Block |
---|
|
<bean id="myRedeliveryPolicy" class="org.apache.camel.processor.RedeliveryPolicy">
<property name="maximumRedeliveries" value="${myprop.max}"/>
</bean>
<!-- here we reference our redelivery policy defined above -->
<onException redeliveryPolicyRef="myRedeliveryPolicy">
<!-- you can define multiple exceptions just adding more exception elements as show below -->
<exception>com.mycompany.MyFirstException</exception>
<exception>com.mycompany.MySecondException</exception>
</onException>
|
Asynchronous Delayed Redelivery
...
In Camel 1.5 the exception clauses has been renamed to onException
and it also supports multiple exception classes:
Code Block |
---|
|
onException(MyBusinessException.class, MyOtherBusinessException.class)
.maximumRedeliveries(2)
.to("activemq:businessFailed");
|
And in Spring DSL you just add another exception element:
Code Block |
---|
|
<onException>
<exception>com.mycompany.MyBusinessException</exception>
<exception>com.mycompany.MyOtherBusinessException</exception>
<redeliveryPolicy maximumRedeliveries="2"/>
<to uri="activemq:businessFailed"/>
</onException>
|
...