我有一条复杂的路线如下(部分):
.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/