Creating a Java bean as the aggregation strategy
To aggregate the messages, we will use a Java bean that will help us build an
aggregation strategy.
-
From the repository tree view, expand the Code node and right click the Beans node. In the contextual menu, select Create Bean.
-
The [New Bean] wizard opens. In the Name field, type in a name for the bean, for
example, AggregateBody. Click Finish to close the wizard. -
Type in the codes as shown in the figure below. In this use case, we just
want to aggregate all messages into a single message.1234567891011121314151617package 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;}} - Press Ctrl+S to save your bean.
Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Login
0 Comments