java - Apache Camel : How to persist property or header between multiple Exchanges after split and subsequent Exception?

标签 java apache-camel spring-camel

我有一条复杂的路线如下(部分):

.when(header("KEY_1").isNull())
.choice()
    .when(header("KEY_2").isNull())
        .split().method(SplitExample.class, "invokeSplitter").streaming().parallelProcessing().executorService(threadPoolExecutor)   // first split                  
            .policy(requires_new)
                .bean(SplitExample.class, "enrich")
                .bean(persister,"populateRecordAndXRef")
                .bean(initializer, "initialize")
                .bean(validator, "validateInMsg")
                .bean(suppressResolver, "resolve")
                .choice()
                    .when(header("KEY_3").isNull())
                        .bean(MsgConverter.class,"doInvoke" )  // #1 property or header set here
                        .split(body()) // second split
                        .bean(validator, "validateOutMsg")                                 
                        .to(toURI.toArray(new String[ toURI.size()]))
                        .process(new Processor() {
                            @Override
                            public void process(Exchange exchange) throws Exception {
                                System.out.println(exchange.getException());  // #2 queue server is shut down here so that transaction failure occurs                                       
                            }
                        })
                    .endChoice() //end when                            
                .end() //end choice
            .end() //end policy                     
        .end() //end split                      
.endChoice() //end when 

我还定义了以下异常(exception)政策:

 onException(JMSException.class)        
    .handled(true)
    .process(new QueueOperationFailureProcessor()); // #3 property or header should be accessible here

现在,我打算在 MsgConverter (#1) 中将一个 bean 设置为 Exchange 属性(“RECOVERY_DETAIL”),并在 QueueOperationFailureProcessor (#3) 中检索相同的 bean >.

通过调试,我可以在在线处理器 (#2) 中看到属性(“RECOVERY_DETAIL”)。在 JMSException 上,当我的异常策略生效时,我想在 QueueOperationFailureProcessor (#3) 中检索属性(“RECOVERY_DETAIL”)。

但碰巧 - QueueOperationFailureProcessor (#3) 中可用的 Exchange 不同于 in-line processor (#2) 中可用的 Exchange,并且找不到属性(“RECOVERY_DETAIL”)。

请帮帮我。

附言我的 camel 版本是 2.16.0,我可能无法使用任何需要升级版本的解决方案。

最佳答案

split 内部发生的异常可能不会一直传播到您的 onException。您可以尝试在 split 中定义一个 doTry/doCatch 来处理这个错误。

关于java - Apache Camel : How to persist property or header between multiple Exchanges after split and subsequent Exception?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55355851/

相关文章:

在 Java 中使用 filewriter 打开文件时出现 java.io.FileNotFoundException

java - 为什么在将持久 activemq 消息更改为非持久消息时无法获得性能提升?

spring-boot - 如何获取从一个路由到另一路由的 header - Camel JavaDsl

java - Camel 中的两条路由是否引用同一个处理 bean 并行执行?

java - 拆分后从 Camel 路由获取原始消息

Java 代码组织 : Where to keep instance of static class

Java 数据库编程 - 为什么这些值不是 "equal"?

java - Maven错误: Package matlabcontrol does not exist

redis - 使用 Redis 的 Camel 保证交付

xml - 事务性 Camel JMS 消费者