gpt4 book ai didi

java - 异常未传播到 Apache Camel 中的错误处理程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:51:59 25 4
gpt4 key购买 nike

我有一个定义了 doTry-doCatch block 的路由。在 doCatch block 中处理异常时,我希望将其传播到错误处理程序,以确保消息在本地处理后被添加到死信队列中。问题是我无法使错误处理程序的传播正常工作(“defaultErrorHandler called!”未打印到控制台)。我也试过 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 中发生的任何事情都不会冒泡到错误处理程序或异常策略。如果你想发送到死信 channel ,你必须在 doCatch 中使用

.to('uri')

关于java - 异常未传播到 Apache Camel 中的错误处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17194871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com