Scenario: Splitting a message and renaming the sub-messages according to contained
information
This scenario applies only to a Talend solution with ESB.
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<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 Java Bean, 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 Java Beans, see
Talend Studio User
Guide.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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"; } } |
Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Login
0 Comments