...
For introduction and background material see Error handling in Camel.
Info | ||
---|---|---|
| ||
In Camel 2.0 onwards there default error handler is changed from Dead Letter Channel to DefaultErrorHandler. This error handler does not support a dead letter queue and will return exceptions back to the caller. This is what you expects when working with regular Java that exceptions will be thrown back to the caller. |
Tip | ||
---|---|---|
| ||
Using Error Handler combined with Exception Clause is a very powerful combination. We encourage end-users to use this combination in your error handling strategies. See samples and Exception Clause. |
...
- DefaultErrorHandler is the default error handler in Camel 2. 0 onwards. This error handler does not support a dead letter queue, it will propagate exceptions back to the caller, as if there where no error handler at all. It has a limited set of features.
- Dead Letter Channel which supports attempting to redeliver the message exchange a number of times before sending it to a dead letter endpoint
- LoggingErrorHandler for just catching and logging exceptions
- NoErrorHandler for no error handling
...
- TransactionErrorHandler is the default error handler in Camel 2.0 onwards for transacted routes. See the Transactional Client EIP pattern.
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
...
title | Transaction in Camel 1.x |
---|
...
...
Short Summary of the provided Error Handlers
DefaultErrorHandler
...
The DefaultErrorHandler is the new default error handler in Camel 2.0. Unlike Dead Letter Channel it does not have any dead letter queue, and do not handle exceptions by default.
Dead Letter Channel
The Dead Letter Channel is the default error handler in Camel 1.x, 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.
...
Wiki Markup |
---|
{snippet:id=e3|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java} |
or in Spring DSL
Code Block | ||||
---|---|---|---|---|
| ||||
<bean id="deadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
<property name="deadLetterUri" value="log:dead"/>
</bean>
<camelContext errorHandlerRef="deadLetterErrorHandler" xmlns="http://camel.apache.org/schema/spring">
...
</camelContext>
|
Code Block | ||||
---|---|---|---|---|
| ||||
<camel:errorHandler id="deadLetterErrorHandler" type="DeadLetterChannel" deadLetterUri="log:dead">
<camel:camelContext errorHandlerRef="deadLetterErrorHandler">
...
</camel:camelContext>
|
Logging Error Handler
The logging error handler will log (by default at ERROR level) whenever an uncaught exception is thrown. The logging category, logger and level may all be defined in the builder.
...
Code Block |
---|
errorHandler(noErrorHandler()); |
TransactionErrorHandler
...
The TransactionErrorHandler is the new default error handler in Camel 2.0 for transacted routes.
Tip | ||||
---|---|---|---|---|
| ||||
If you have marked a route as transacted using the transacted DSL then Camel will automatic use a TransactionErrorHandler. It will try to lookup the global/per route configured error handler and use it if its a |
Features support by various Error Handlers
In Camel 1.x the TransactionErrorHandler only supports the all scopes feature. In Camel 2.0 we have redone it to be based on the same core class as the DefaultErrorHandler and hence why it supports the same feature set as this.
Here is a breakdown of which features is supported by the Error Handler(s):
...
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 The error handler can be configured as a spring bean and scoped in:
...
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.
...
- Error handling in Camel for introduction and background material on error handling in Camel
- Dead Letter Channel for the default dead letter error handler in Camel 1.x
- DefaultErrorHandler for the default error handler in Camel 2.0 onwards
- TransactionErrorHandler for the default error handler for transacted routes in Camel 2.0 onwards
- Transactional Client for transactional behavior
- Exception Clause as it supports handling thrown exceptions
- Try Catch Finally for try ... catch ... finally as DSL you can use in the routing