apache-camel - Camel 多播异常传播

标签 apache-camel

当异常在多播内部抛出时,Camel 不会传播异常。

考虑到以下设置,其中 direct:route 从其 beanRef 抛出异常:

        rest("/...")
        .post()
        .consumes("application/json")
        .produces("application/json")
        .route()
            .onException(Exception.class)
                .handled(true)
                .bean("exceptionHandler")
                .marshal("exceptionDataFormat")
            .end()
            .unmarshal("dataFormat")
            ...
            .enrich("direct:services", new ServiceAggregator())
            .to("direct:anotherRoute")
            ...
        .end()
    .endRest();


    from("direct:services")
        .errorHandler(noErrorHandler())
        .multicast()
        .setAggregationStrategy(new GroupedExchangeAggregationStrategy())
        .executorServiceRef("executor")
        .parallelAggregate()
        .streaming()
        .stopOnException()
            .to("direct:route")
        .end()
    .end();

    from("direct:route")
        .errorHandler(noErrorHandler())
        .bean("someRef", "someMethod")
    .end();

我没有让异常处理程序使用交换并处理错误,而是立即返回以下异常(到 SoapUI):

org.apache.camel.CamelExchangeException: Parallel processing failed for number 0. Exchange[...] at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:328)
at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:299)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

并且父路由以该异常结束并且没有异常处理。

如果 direct:anotherRoute 抛出异常,则该异常会被正确处理。

为什么我无法将多播异常(exception)传播到父路由?

Camel 2.17-SNAPSHOT

最佳答案

打开多播上的shareUnitOfWork选项。查看更多详细信息:http://camel.apache.org/multicast分割器上有一个示例,也有此选项: http://camel.apache.org/splitter.html

关于apache-camel - Camel 多播异常传播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35896325/

相关文章:

java - Netty4 - TCP 服务器 - 使用 Camel 进行基本测试

java - 如何使用camel删除超过几天的文件夹

java - Camel kafka maxPollRecords配置是什么意思

apache-camel - Jboss Fuse ESB 入门

apache-camel - JMS事务简单示例

java - Camel .beanRef 已弃用 - 现在如何在 Java DSL 路由中访问容器管理的 bean?

java - 多线程执行@Handler方法

java - Apache Camel + RabbitMQ。端点未创建

java - 交换消息标题格式

java - mock 幂等消费者