...
Code Block |
---|
errorHandler(noErrorHandler()); |
...
Scopes
The error handler is scoped as either
- global
- per route specific
- or policy based (this applies for transactional exchanges only)
The following example shows how you can register a global error handler (in this case using the logging handler)
Wiki Markup |
---|
{snippet:id=e1|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java} |
Setting error handlers on a specific route
The following example shows how you can register a local route specific error handler; the customized logging handler is only registered for the route from Endpoint seda:a
Wiki Markup |
---|
{snippet:id=e2|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java} |
Spring based configuration
Available as of Camel 1.4
Info | ||
---|---|---|
| ||
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 referenced as eitherscoped in:
- global (the camelContext tag)
- per route (the route tag)
- per policy (the policy tag)
...
Wiki Markup |
---|
{snippet:id=e2|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DeadLetterChannelRedeliveryConfigTest-context.xml} |
Redelivery Policy
You can also configure the RedeliveryPolicy as this example shows
Wiki Markup |
---|
{snippet:id=e4|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java} |
And configuration of the redelivery policy in Spring DSL is as:
Wiki Markup |
---|
{snippet:id=e1|lang=xml|url=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml} |
...
. |
...
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 redelivy policy defined above --> <redeliveryPolicy ref="myRedeliveryPolicy"/> </onException> |
Using the transactional error handler
...