2

我想拆分交换消息正文(它是 MyCustomClass 对象的列表),处理它们(一个接一个),然后它们将所有交换聚合在一起。拆分可以,一个一个处理也可以,但是我不知道如何聚合它们。

from("mysource")
    .unmarshal(new ListJacksonDataFormat(MyClass.class))
    .split().body()
    .process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            // process MyClass item
            exchange.getIn().setBody(processedItem);
        }
    })
    .to("destinationForProcessedItem")
    .aggregate(new GroupedExchangeAggregationStrategy()) <== Seems like problem is here
    .process(new Processor() {
            // handle result of aggregation
    })

我不需要复杂的聚合,只需收集拆分的 Exchange 列表并在最终处理器中处理它们。

4

2 回答 2

1

使用拆分器中的内置聚合器,请参阅组合消息处理器 EIP 模式:https ://camel.apache.org/components/latest/eips/composed-message-processor.html#_sample 。

于 2017-11-02T07:26:42.403 回答
0

像这样写

         .aggregate(new AggregationStrategy() {
                @Override
                public Exchange aggregate(Exchange exchange, Exchange exchange1) {
                    //logic for aggregation using exchnage and exchange1
                }
            })
于 2017-11-02T05:41:10.837 回答