我有一个定义 doTry-doCatch 块的路线。当在 doCatch 块中处理异常时,我希望将其传播到错误处理程序,以确保在本地处理消息后将消息添加到死信队列。问题是我无法让错误处理程序的传播工作(“调用defaultErrorHandler!”未打印到控制台)。我也尝试过 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");
}
};
}