To aggregate the messages, we will use a Java bean that will help us build an aggregation strategy.
package beans; import org.apache.camel.Exchange; import org.apache.camel.processor.aggregate.AggregationStrategy; public class AggregateBody implements AggregationStrategy{ public Exchange aggregate(Exchange oldEx, Exchange newEx) { if(oldEx==null){ return newEx; } String oldBody = oldEx.getIn().getBody(String.class); String newBody = newEx.getIn().getBody(String.class); newEx.getIn().setBody(oldBody+newBody); return newEx; } }
If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!