max*_*dev 3 java osgi apache-camel blueprint apache-karaf
我有以下骆驼路线设置:
<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>
Run Code Online (Sandbox Code Playgroud)
在itemProcessor我想计算通过将属性放入交换而成功处理的项目数:
exchange.setProperty("PROCESSED_ITEMS", exchange.getProperty("PROCESSED_ITEMS", Integer.class) + 1);
Run Code Online (Sandbox Code Playgroud)
由于某种原因,每次调用处理器时,该属性都会再次为空。文档说:
Exchange 还在其整个生命周期内保存元数据,这些元数据存储为可使用各种 getProperty(String) 方法访问的属性。
https://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html
最初在 中设置属性时collectItemsProcessor,会保留该值。我怀疑每次调用分割路由时都会复制交换,但是我怎样才能真正保留“整个生命周期内的元数据”?
Split 为每个项目创建一个新的交换。此交换的生命周期仅涵盖拆分元素内部的内容。
如果您只想处理已处理元素的计数器,则只需使用属性“CamelSplitIndex”即可。拆分器会自动填充此属性。
| 归档时间: |
|
| 查看次数: |
3550 次 |
| 最近记录: |