简体   繁体   English

Apache camel onException 向原始消息添加错误详细信息

[英]Apache camel onException adding error details to the original message

I have added this exception handling to the camel route.我已将此异常处理添加到骆驼路线。

 .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());
    }
}

When I read this message back from the error queue, I cannot find this header.当我从错误队列读回这条消息时,我找不到这个标头。 any idea on how to add error details along with the original message to the error queue关于如何将错误详细信息与原始消息一起添加到错误队列的任何想法

This could be a context problem because you are in a processor that is called by the error handler .这可能是上下文问题,因为您位于错误处理程序调用的处理器中

As an alternative, you could return the String value to set in the header from your processor method .作为替代方法,您可以返回 String 值以您的处理器方法的标头中设置 By the way, this also improves the testability of your Processor.顺便说一下,这也提高了处理器的可测试性

Then you can use this return value to set the header in the error handler route directly.然后你可以使用这个返回值直接在错误处理程序路由中设置头

.setHeader("FailedBecause", method(new OnExceptionProcessor()))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM