骆驼交换属性在分裂过程中丢失

Camel exchange properties lost during split

我有以下骆驼路线设置:

<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);

出于某种原因,在每次调用处理器时,属性 再次为空。文档说:

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 中设置 属性 时,将保留此值。我怀疑每次调用拆分路由都会复制交换,但是我怎么才能真正保留 "meta-data during the entire lifetime"?

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

如果您只想要一个已处理元素的计数器,那么只需使用 属性 "CamelSplitIndex"。拆分器会自动填充此 属性.