java-异常未传播到Apache Camel中的错误处理程序
作者:互联网
我有一个定义doTry-doCatch块的路由.当在doCatch块中处理异常时,我希望将其传播到错误处理程序,以确保在本地处理该消息后将其添加到死信队列中.问题是我无法传播到错误处理程序以正常工作(“ defaultErrorHandler named!”未打印到控制台).我也尝试了onException,但也没有运气.
任何提示,不胜感激.
问候,奥利弗
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
errorHandler(deadLetterChannel("ref:myDLQ")
.log("defaultErrorHandler called! ${body}"));
final RouteDefinition route = from("seda:queue.inbox");
route
.doTry()
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("throwing ex");
throw new IllegalArgumentException("test");
}
})
.doCatch(Exception.class)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("handling ex");
route.log(LoggingLevel.ERROR, "Exception in route: ${body}");
throw new IllegalArgumentException("rethrow");
}
})
.log("Received order ${body}")
.to("mock:queue.order");
}
};
}
解决方法:
根据this
Camel error handling is disabled
When using doTry .. doCatch .. doFinally then the regular Camel Error Handler does not apply. That means any onException or the likes does not trigger. The reason is that doTry .. doCatch .. doFinally is in fact its own error handler and that it aims to mimic and work like how try/catch/finally works in Java.
通过我自己的实验,我可以验证doTry内发生的任何事情都不会冒泡到错误处理程序或异常策略中.如果您想发送到一个死信通道,则必须在doCatch中使用
.to('uri')
标签:apache-camel,java 来源: https://codeday.me/bug/20191123/2065365.html