【问题标题】:Camel exchange properties lost during split拆分期间丢失的骆驼交换属性
【发布时间】:2016-12-22 12:57:10
【问题描述】:

我有以下骆驼路线设置:

<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成功处理的item数量:

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

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

交易所还在其整个生命周期内将元数据保存为 使用各种 getProperty(String) 方法访问的属性。

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

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

【问题讨论】:

    标签: java apache-camel osgi apache-karaf blueprint


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-05-16
      • 2017-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多