Scenario: Routing files conditionally to different file paths
This scenario applies only to a Talend solution with ESB.
In this scenario, three file messages containing people information are routed to
different endpoints according to the city names they contain.
The following is an extract of the example XML files used in this use case:
Message_1.xml:
1 2 3 4 5 |
<person> <firstName>Ellen</firstName> <lastName>Ripley</lastName> <city>Washington</city> </person> |
Message_2.xml:
1 2 3 4 5 |
<person> <firstName>Peter</firstName> <lastName>Green</lastName> <city>London</city> </person> |
Message_3.xml:
1 2 3 4 5 |
<person> <firstName>Alice</firstName> <lastName>Yang</lastName> <city>Beijing</city> </person> |
A predefined Java bean, setDynaURI, is called in this use case to
return endpoint URIs according to the city name contained in each message, so that the
message containing the city name Washington will be routed to
endpoint Washington and so forth.
For more information about creating and using Java Beans, see
Talend Studio User
Guide.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package beans; import org.apache.camel.Exchange; import org.apache.camel.Header; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class setDynaURI { public String setURI(Document document, @Header(Exchange.SLIP_ENDPOINT) String previous) { if(previous!=null){ return null; } NodeList cities = document.getDocumentElement().getElementsByTagName( "city"); Element city = (Element) cities.item(0); String textContent = city.getTextContent(); return "direct:"+textContent; } } |
Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Login
0 Comments