2

I'd like to split exchange message body (it's list of MyCustomClass object), process them (one by one) and them aggregate the all exchanges together. Split is ok, process one by one also ok, but I can't figure out how to aggregate them.

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

I don't need complicated aggregation, just collect list of splitted Exchanges and handle them in the final processor.

Junior5413
  • 83
  • 1
  • 2
  • 4

2 Answers2

1

Use the built-in aggregator in the splitter, see the composed message processor EIP pattern: https://camel.apache.org/components/latest/eips/composed-message-processor.html#_sample.

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
0

write like this

         .aggregate(new AggregationStrategy() {
                @Override
                public Exchange aggregate(Exchange exchange, Exchange exchange1) {
                    //logic for aggregation using exchnage and exchange1
                }
            })
rathna
  • 1,055
  • 2
  • 11
  • 23