Error HandlerCamel supports pluggable ErrorHandler
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 examlpes. Setting global error handlersThe following example shows how you can register a global error handler (in this case using the logging handler) RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() { public void configure() { errorHandler(loggingErrorHandler("FOO.BAR")); from("queue:a").to("queue:b"); } }; Setting error handlers on a specific routeThe following example shows how you can register a local error handler; the customized logging handler is only registered for the route from Endpoint queue:a RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() { public void configure() { from("queue:a").errorHandler(loggingErrorHandler("FOO.BAR")).to("queue:b"); // this route will use the default error handler, DeadLetterChannel from("queue:b").to("queue:c"); } }; Default Error HandlerThe 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 RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() { public void configure() { errorHandler(deadLetterChannel("queue:errors")); from("queue:a").to("queue:b"); } }; You can also configure the RedeliveryPolicy RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() { public void configure() { errorHandler(deadLetterChannel("queue:errors").maximumRedeliveries(2).useExponentialBackOff()); from("queue:a").to("queue:b"); } }; |