gpt4 book ai didi

java - Camel 交换 split 期间丢失的属性(property)

转载 作者:行者123 更新时间:2023-12-01 09:05:59 25 4
gpt4 key购买 nike

我有以下 Camel 路线设置:

<route id="firstRoute">
<from uri="..." />

<!-- This processor puts a list of items as the out body -->
<process ref="collectItemsProcessor" />

<!-- Now all items should be processed one by one: -->
<split>
<simple>${body}</simple>
<to uri="direct:secondRoute" />
</split>
</route>

<route id="secondRoute">
<from uri="direct:secondRoute" />

<process ref="itemProcessor" />
</route>

itemProcessor 中,我想计算通过将属性放入交换中成功处理的项目数:

exchange.setProperty("PROCESSED_ITEMS", exchange.getProperty("PROCESSED_ITEMS", Integer.class) + 1);

由于某种原因,每次调用处理器时,该属性都会再次为 null。文档说:

The Exchange also holds meta-data during its entire lifetime stored as properties accessible using the various getProperty(String) methods.

https://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html

最初在collectItemsProcessor中设置属性时,会保留该值。我怀疑每次调用分割路由时都会复制交换,但是我怎样才能真正保留“整个生命周期内的元数据”?

最佳答案

Split 为每个项目创建一个新的交换。此交换的生命周期仅涵盖 split 元素内部的内容。

如果您只想处理已处理元素的计数器,则只需使用属性“CamelSplitIndex”即可。拆分器会自动填充此属性。

关于java - Camel 交换 split 期间丢失的属性(property),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41283704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com