Apache Camel中的拆分和聚合

时间:2017-11-01 22:10:52

标签: apache-camel eip

我想拆分交换邮件正文(它的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列表并在最终处理器中处理它们。

2 个答案:

答案 0 :(得分:0)

像这样写

         .aggregate(new AggregationStrategy() {
                @Override
                public Exchange aggregate(Exchange exchange, Exchange exchange1) {
                    //logic for aggregation using exchnage and exchange1
                }
            })

答案 1 :(得分:0)

在拆分器中使用内置聚合器,请参阅标题为仅使用拆分器的示例的部分中的组合消息处理器EIP模式:http://camel.apache.org/composed-message-processor.html

相关问题