Using cSplitter to split a message and aggregate replies from sub-messages - 7.0

Splitter - Mediation

EnrichVersion
7.0
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
EnrichPlatform
Talend Studio
task
Data Governance > Third-party systems > Routing components (Mediation) > Splitter components (Mediation)
Data Quality and Preparation > Third-party systems > Routing components (Mediation) > Splitter components (Mediation)
Design and Development > Third-party systems > Routing components (Mediation) > Splitter components (Mediation)

This scenario applies only to Talend Open Studio for ESB, Talend ESB, Talend Data Services Platform, Talend MDM Platform, Talend Real Time Big Data Platform and Talend Data Fabric.

For more technologies supported by Talend, see Talend Mediation Components.

In this scenario, we will use the cSplitter component to split a message and aggregate the replies from sub-messages.

A predefined Java Bean, AppendAggregator will be called to as the strategy to aggregate the replies from sub-messages. For more information about creating and using JavaBeans, see Talend Studio User Guide.

package beans;
import org.apache.camel.Exchange;
import org.apache.camel.processor.aggregate.AggregationStrategy;

public class AppendAggregator 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 + "\n" + newBody);
		return newEx;
	}
}