【问题标题】:Apache camel onException adding error details to the original messageApache camel onException 在原始消息中添加错误详细信息
【发布时间】:2021-10-19 14:35:48
【问题描述】:

我已将这个异常处理添加到骆驼路线中。

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

当我从错误队列中读回此消息时,我找不到此标头。 关于如何将错误详细信息与原始消息一起添加到错误队列的任何想法

【问题讨论】:

  • 也许将它包裹在一个物体中?

标签: java apache-camel mq


【解决方案1】:

这可能是上下文问题,因为您处于错误处理程序调用的处理器中

作为替代方案,您可以在 从您的处理器方法的标头中返回要设置的字符串值。顺便说一句,这也提高了处理器的可测试性

那么你可以直接使用这个返回值在错误处理路由中设置header

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多