![](/img/trans.png)
[英]Apache Camel onException Custom Error Handler is not working
[英]Apache camel onException adding error details to the original message
我已将此异常处理添加到骆驼路线。
.onException(BeanCreationException.class, ValidationException.class)
.handled(true)
.process(new OnExceptionProcessor())
.to("errorQueue0").id("errorQueue")
.end()
public class OnExceptionProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
exchange.getIn().setHeader("FailedBecause", cause.getMessage());
}
}
当我从错误队列读回这条消息时,我找不到这个标头。 关于如何将错误详细信息与原始消息一起添加到错误队列的任何想法
这可能是上下文问题,因为您位于错误处理程序调用的处理器中。
作为替代方法,您可以返回 String 值以在您的处理器方法的标头中设置。 顺便说一下,这也提高了处理器的可测试性。
然后你可以使用这个返回值直接在错误处理程序路由中设置头。
.setHeader("FailedBecause", method(new OnExceptionProcessor()))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.