Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 Handlers

Default 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:

Wiki Markup
{snippet:id=e3|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java}

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(loggingErrorHandler("mylogger.name").level(LoggingLevel.INFO));

This would create an error handler which logs exceptions using the category mylogger.name and uses the level INFO for all log messages created.

Code Block

from("seda:a").errorHandler(loggingErrorHandler("mylogger.name").level(LoggingLevel.DEBUG)).to("seda:b");

Loggers may also be defined for specific routes.

No Error Handler

The no error handler is to be used for disabling error handling.

Code Block

errorHandler(noErrorHandler());

Setting global error handlers

...

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}

Default Error Handler

Redelivery Policy

You can also configure the RedeliveryPolicy as this example showsThe default error handler is the Dead Letter Channel which is automatically configured for you. You can then configure the specific dead letter endpoint to use either for an entire rule base or a specific rule as shown above. For example

Wiki Markup
{snippet:id=e3e4|lang=java|url=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java}

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(loggingErrorHandler("mylogger.name").level(LoggingLevel.INFO));

This would create an error handler which logs exceptions using the category mylogger.name and uses the level INFO for all log messages created.

Code Block

from("seda:a").errorHandler(loggingErrorHandler("mylogger.name").level(LoggingLevel.DEBUG)).to("seda:b");

Loggers may also be defined for specific routes.

Overriding default behavior

You can also configure the RedeliveryPolicy as this example showsAnd configuration of the redelivery policy in Spring DSL is as:

Wiki Markup
{snippet:id=e4e1|lang=javaxml|url=activemq/camel/trunk/components/camel-corespring/src/test/javaresources/org/apache/camel/spring/processor/builderonexception/ErrorHandlerTestexceptionBuilderWithRetryLoggingLevelSet.javaxml}

Exception Policy Strategy

As of Camel 1.4 you can configure the ExceptionPolicyStrategy as this example shows. Notice that we use Exception Clause to handle known exceptions being thrown.

...