Splitting a message and renaming the sub-messages according to contained information - 7.3

SetHeader (Mediation)

Version
7.3
Language
English
Product
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Data Governance > Third-party systems > Processing components (Mediation) > SetHeader components (Mediation)
Data Quality and Preparation > Third-party systems > Processing components (Mediation) > SetHeader components (Mediation)
Design and Development > Third-party systems > Processing components (Mediation) > SetHeader components (Mediation)
Last publication date
2023-06-12

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, a file message containing people information is split into sub-messages. Each sub-messages is renamed according the city name it contains, and then routed to another endpoint.

The following is the example XML file used in this use case:

<people>
    <person>
        <firstName>Pierre</firstName>
        <lastName>Dubois</lastName>
        <city>Paris</city>
    </person>
    <person>
        <firstName>Nicolas</firstName>
        <lastName>Yang</lastName>
        <city>Beijing</city>
    </person>
    <person>
        <firstName>Ellen</firstName>
        <lastName>Ripley</lastName>
        <city>Washington</city>
    </person>
</people>

A predefined JavaBean, setFileNames, is called by the cSetHeader component used in this use case to define a file name for each message according to the city name it contains. For more information about creating and using JavaBeans, see Talend Studio User Guide.

package beans;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class setFileNames {
	public String getCityName(Document document) {
		NodeList cities = document.getDocumentElement().getElementsByTagName(
				"city");
		Element city = (Element) cities.item(0);
		String textContent = city.getTextContent();
			return textContent+".xml";
		}
}