Page Edited :
CAMEL :
Error Handler
Error Handler has been edited by Claus Ibsen (Jan 03, 2009). Change summary: polished Error HandlerCamel supports pluggable ErrorHandler strategies to deal with errors processing an Event Driven Consumer. An alternative is to specify the error handling directly in the DSL using the Exception Clause. 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 HandlersDefault Error Handler (Dead Letter Channel)The default error handler is the Dead Letter Channel which is automatically configured for you. By default Camel will redeliver at most 6 times using 1 second delay, and if the exchange failed it will be logged at ERROR level. You can configure the default dead letter endpoint to use: RouteBuilder builder = new RouteBuilder() { public void configure() { errorHandler(deadLetterChannel("seda:errors")); from("seda:a").to("seda:b"); } };
The following example shows how you can register a global error handler (in this case using the logging handler) RouteBuilder builder = new RouteBuilder() { public void configure() { errorHandler(loggingErrorHandler("FOO.BAR")); from("seda:a").to("seda:b"); } }; The following example shows how you can register a route specific error handler; the customized logging handler is only registered for the route from Endpoint seda:a RouteBuilder builder = new RouteBuilder() { public void configure() { from("seda:a").errorHandler(loggingErrorHandler("FOO.BAR")).to("seda:b"); // this route will use the default error handler, // DeadLetterChannel from("seda:b").to("seda:c"); } }; Spring based configurationAvailable as of Camel 1.4
In Camel 1.4 the error handler can be configured as a spring bean and scoped in:
The error handler is configured with the errorHandlerRef attribute.
Spring based configuration sampleIn 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. <camelContext id="camel" xmlns="http://activemq.apache.org/camel/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. <!-- 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="defaultDeadLetterEndpointUri" 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 handlerThe 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 alsoThe Dead Letter Channel for further details. |
Unsubscribe or edit your notifications preferences