Page Edited :
CAMEL :
Error Handler
Error Handler has been edited by Claus Ibsen (Apr 02, 2009). Content:Error HandlerCamel supports pluggable ErrorHandler Some current implementations include
These error handlers can be applied in the DSL to an entire set of rules or a specific routing rule as we show in the next examples. Error handling rules are inherited on each routing rule within a single RouteBuilder Short Summary of the provided Error HandlersDefaultErrorHandler
|
Java DSL vs. Spring DSL The error handler is configured a bit differently in Java DSL and Spring DSL. Spring DSL relies more on standard Spring bean configuration whereas Java DSL uses fluent builders. |
In Camel 1.4 the error handler can be configured as a spring bean and scoped in:
- global (the camelContext tag)
- per route (the route tag)
- per policy (the policy tag)
The error handler is configured with the errorHandlerRef attribute.
Error Handler Hierarchy The error handlers is inherited, so if you only have set a global error handler then its use everywhere. But you can override this in a route and use another error handler. |
Spring based configuration sample
In this sample we configure a Dead Letter Channel on the route that should redeliver at most 3 times and use a little delay before retrying.
First we configure the reference to myDeadLetterErrorHandler using the errorHandlerRef attribute on the route tag.
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <template id="myTemplate"/> <!-- set the errorHandlerRef to our DeadLetterChannel, this applies for this route only --> <route errorHandlerRef="myDeadLetterErrorHandler"> <from uri="direct:in"/> <process ref="myFailureProcessor"/> <to uri="mock:result"/> </route> </camelContext>
Then we configure myDeadLetterErrorHandler that is our Dead Letter Channel. This configuration is standard Spring using the bean element.
And finally we have another spring bean for the redelivery policy where we can configure the options for how many times to redeliver, delays etc.
<!-- here we configure our DeadLetterChannel --> <bean id="myDeadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder"> <!-- exchanges is routed to mock:dead in cased redelivery failed --> <property name="deadLetterUri" value="mock:dead"/> <!-- reference the redelivery policy to use --> <property name="redeliveryPolicy" ref="myRedeliveryPolicyConfig"/> </bean> <!-- here we set the redelivery settings --> <bean id="myRedeliveryPolicyConfig" class="org.apache.camel.processor.RedeliveryPolicy"> <!-- try redelivery at most 3 times, after that the exchange is dead and its routed to the mock:dead endpoint --> <property name="maximumRedeliveries" value="3"/> <!-- delay 250ms before redelivery --> <property name="delay" value="250"/> </bean>
Using the transactional error handler
The transactional error handler is introduced in Camel 1.4 and is based on spring transaction. This requires the usage of the camel-spring component.
See Transactional Client that has many samples for how to use and transactional behavior and configuration with this error handler.
See also
The Dead Letter Channel for further details.
The Transactional Client for transactional behavior
The Exception Clause as it supports handling thrown exceptions
Unsubscribe or edit your notifications preferences