Routing each message conditionally to a series of endpoints - Cloud - 8.0

Routing Slip (Mediation)

Version
Cloud
8.0
Language
English
Product
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Data Governance > Third-party systems > Routing components (Mediation) > Routing Slip components (Mediation)
Data Quality and Preparation > Third-party systems > Routing components (Mediation) > Routing Slip components (Mediation)
Design and Development > Third-party systems > Routing components (Mediation) > Routing Slip components (Mediation)
Last publication date
2024-02-21

This scenario applies only to 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, which is based on the previous scenario, each message from a file system is routed consecutively to different endpoints according to the city name it contains.

All files used in this use case are named after the city name they contain. The following are the extracts of two examples:

Beijing.xml:

<person>
    <firstName>Nicolas</firstName>
    <lastName>Yang</lastName>
    <city>Beijing</city>
</person>

Paris.xml:

<person>
  <firstName>Pierre</firstName>
  <lastName>Dupont</lastName>
  <city>Paris</city>
</person>

A predefined JavaBean, setEndpoints, is called in this use case to return endpoint URIs according to the city name contained in each message, so that the messages will be routed as follows:

  • The message containing the city name Paris will be routed first to endpoint a, then to endpoint b, and finally to endpoint c.

  • The message containing the city name Beijing will be routed first to endpoint c, then to endpoint a, and finally to endpoint b.

  • Any other messages will be routed to endpoint b and then to endpoint c.

For more information about creating and using JavaBeans, see Using Beans.

package beans;

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

public class setEndpoints {
	public String helloExample(Document document) {
		NodeList cities = document.getDocumentElement().getElementsByTagName(
				"city");
		Element city = (Element) cities.item(0);
		String textContent = city.getTextContent();
		if ("Paris".equals(textContent)) {
			return "direct:a,direct:b,direct:c";
		} else if ("Beijing".equals(textContent)) { 
			return "direct:c,direct:a,direct:b";
		} else
			return "direct:b,direct:c";
	}
}