防止改变父母交换财产

时间:2017-06-30 15:31:07

标签: java apache-camel

我定义了以下路线:

<route id="operation-456">
    <from uri="direct:operation-456" />
    <setProperty propertyName="operationid">
        <constant>456</constant>
    </setProperty>
    <!-- read file -->
</route>

<route id="operation-123">
    <from uri="direct:operation-123" />
    <setProperty propertyName="operationid">
        <constant>123</constant>
    </setProperty>
    <enrich strategyRef="aggregators.MergeListAggregator" shareUnitOfWork="true">
        <constant>direct:operation-456</constant>
    </enrich>
    <to uri="bean:UpdateStocksProcessor" />
</route>

当我尝试访问属性operationId时,我得到456而不是原始操作值123.

我怀疑富集只能丰富身体,但不会丰富头部和属性。有没有办法跳过更改交换属性或以某种方式隔离值?

编辑:MergeListAggregator

public class MergeListAggregator implements AggregationStrategy {
    @Override
    public Exchange aggregate(Exchange original, Exchange resource) {
        List<Map<String, Object>> main = (List<Map<String, Object>>) original.getIn().getBody();
        if(main == null) {
            main = new ArrayList<>();
        }

        List<Map<String, Object>> additional = (List<Map<String, Object>>) resource.getIn().getBody();
        if(additional == null) {
            additional = new ArrayList<>();
        }

        main.addAll(additional);

        original.getOut().setBody(main);

        return original;
    }
}

1 个答案:

答案 0 :(得分:0)

是的,你可以完全控制如何在AggregationStrategy中丰富你可以做任何你想要/保留在你返回的Exchange实例中的结果。

请看看如何实施aggregators.MergeListAggregator