Apache Camel:在拆分和随后的异常之后,如何在多个Exchange之间保留属性或标头?

San*_*aha 5 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 
Run Code Online (Sandbox Code Playgroud)

我还定义了以下异常策略:

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

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

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

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

请帮帮我。

PS我的骆驼版本为2.16.0,我可能无法使用需要版本升级的任何解决方案。

小智 0

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