For future readers, this is the solution I use for camel error handling (this is all a java config, but it will work like spring xml):
1) Install a DeadLetterChannelBuilder Bean
@Bean public DeadLetterChannelBuilder myErrorHandler() { DeadLetterChannelBuilder deadLetterChannelBuilder = new DeadLetterChannelBuilder(); deadLetterChannelBuilder.setDeadLetterUri("direct:error"); deadLetterChannelBuilder.setRedeliveryPolicy(new RedeliveryPolicy().disableRedelivery()); deadLetterChannelBuilder.useOriginalMessage(); return deadLetterChannelBuilder; }
Now this bean will be responsible for collecting errors and forwarding them to the direct:error URI.
2) Set up the error handling route
You will need a route to listen in the direct:error URI, because now your routes are routed.
@Override public void configure() throws Exception { from("direct:error") .to("log:error") .end(); }
As you now see, all your errors are redirected to the above route, you have the flexibility to implement complex error handling logic around the world.
3) Add your global error handler to your routes
You still need to introduce bean error handling into each route. I want the camel to handle this automatically, but I have not found a way. Although with this approach, code duplication / overhead is minimal.
@Override public void configure() throws Exception { errorHandler(myErrorHandler) from("myStartingUri") .to("myEndDestination") .end(); }
Looking at the documentation for the springs xml configuration, I think you will need to put <route errorHandlerRef="myErrorHandler"> in the route definition.
source share