Creating the route

Talend Data Fabric Getting Started Guide

EnrichVersion
6.1
EnrichProdName
Talend Data Fabric
task
Data Governance
Design and Development
Data Quality and Preparation
EnrichPlatform
Talend Studio
  1. First, switch from the Integration perspective to the Mediation perspective by clicking Mediation in the top right hand corner.

  2. Create a new route by right-clicking Routes > Create Route. Give the name SayHelloRoute and purpose is Demo, and click Finish.

    The Route SayHelloRoute 0.1 tab opens.

  3. Now you will notice that the palette has changed from the one in the Integration perspective to the Mediation perspective. You will create a typical content-based route, dragging and dropping components from the palette to the route grid.

    The request message is coming in from the consumer, so drag and drop the Connectivity > Services > cCXF component, which intercepts messages coming into server endpoints.

    Then, as you want to create a content-based route, drag and drop the Routing > cMessageRouter component, which reroutes messages depending on a set of conditions.

    Then add one more Connectivity > Services > cCXF for the target service, and a Custom > cProcessor to return error messages.

    Note

    Having multiple cCXF components with the same label in a Route is not supported.

    It is recommended to label each component with a unique name to better identify its role in the Route.

    Having duplicate labels may cause problems for the code generation of some components.

  4. To implement this, just add some parameters. So, click cCXF_1, and then click the Component tab below:

    • As a Talend Open Studio for ESB first time user, you will be asked to install external libraries in the Studio to be able to use some components as the cCXF, so please follow the instructions and install them.

    • In the Address field, paste in the previous service address "http://localhost:8090/services/SayHelloService", and update the port to be 8092, since the new service will be listening on this port. So, you get the following new service address "http://localhost:8092/services/SayHelloService".

    • In the Wsdl File field, specify the URL of the WSDL from the original service. Use the http:// address to get the live background service information. It is in "http://localhost:8090/services/SayHelloService?WSDL".

    • In the Dataformat list, select PAYLOAD, as you are looking at the message body.

    Note

    At any point, you can save the current information by selecting File > Save or clicking the Save icon in the top left hand corner.

  5. Repeat the previous step for the cCXF_2: - except that the port number in the Address field is 8090.

  6. Configure the cProcessor component to return error messages. Double-click it in the design workspace to show its Basic settings view in the Component tab.

    In the Code box, enter throw new Exception("user name error") to throw an exception.

  7. So now, connect the components together. Connect cCXF_1 to cMessageRouter_1 by right-clicking the center of cCXF_1 and selecting Row > Route and dropping the end onto cMessageRouter_1.

  8. Then create a When trigger for the service, by right-clicking cMessageRouter_1, selecting Trigger > When and dropping the end on cCXF_2.

  9. Similarly, add an Otherwise trigger from cMessageRouter_1 to cProcessor_1 by right-clicking cMessageRouter_1, selecting Trigger > Otherwise and dropping the end on cProcessor_1.

    So, in summary, you create a request on port 8092 (cCXF_1), and send it to either port 8090 (cCXF_2) or the cProcessor endpoint, depending on the contents of the message.

    This results in the following:

  10. Configure the When condition: right-click the when1 line, which brings up a small dialog.

    In the Type list, select simple, and the Condition is "${bodyAs(String)} contains 'Alice'".

    This way, any message with "Alice" in the body will be routed to the service that listens on port 8090.