Scenario: Exchanging messages between a Job and a Route - 6.1

Talend Components Reference Guide

EnrichVersion
6.1
EnrichProdName
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

This scenario describes how to exchange messages between a Job and a Route using the tRouteInput and the tRouteFault component. To do this, a Job is created to receive the message from the Route and mark the message as fault. Then a Route is built to send the message to the Job and handle the fault message.

For more information about how to use the Mediation components, see Talend ESB Mediation Components Reference Guide.

Creating an Data Integration Job

In this section, a Job named RouteCommunication_tRouteFault is built in the Mediation perspective of the Studio.

Dropping and linking the components
  1. Drag and drop a tRouteInput and a tRouteFault from the Palette onto the design workspace.

  2. Right-click the tRouteInput component, select Row > Main from the contextual menu and click the tRouteFault component.

Configuring the components
  1. Double-click the tRouteInput component to open its Basic settings view in the Component tab.

  2. Click the three-dot button next to Edit Schema. In the schema dialog box, click the plus button to add a new line of String type and name it body. Click OK to close the dialog box.

  3. In the Simple Expression field for the body element, enter "${in.body}" to get the body of the input message from the Route.

  4. Double-click the tRouteFault component to display its Basic settings view in the Component tab.

  5. Make sure that tRouteFault has one element body. Set its type to Body.

  6. Press Ctrl+S to save your Job.

Creating a Mediation Route

In this section, we will switch to the Mediation perspective and create a Route to send a message to the Job and handle the fault message.

Dropping and linking the components
  1. Drag and drop a cTimer, a cSetBody, a cJavaDSLProcessor, a cTalendJob, a cOnException and a cProcessor component from the Palette onto the design workspace.

  2. Link the components with the Row > Route connection as shown above.

  3. Label the components for better identification of their roles.

Configuring the components
  1. Double-click the cTimer component to open its Basic settings view in the Component tab.

  2. Enter 1 in the Repeat field to trigger a message exchange one time.

  3. Double-click the cSetBody component to display its Basic settings view in the Component tab.

  4. Select Simple from the Language list and enter Hello! in the Expression field.

  5. Double-click the cJavaDSLProcessor component to open its Basic settings view in the Component tab.

  6. Enter .handleFault() in the Code box so that the fault message will be caught as an exception.

  7. Double-click the cTalendJob component to display its Basic settings view in the Component tab.

  8. Select Job RouteCommunication_tRouteFault from the repository to call the Job that is created in the previous section.

  9. Double click the cOnException component to display its Basic settings view in the Component tab.

  10. Click [+] to add a line to the Exceptions table, and enter org.apache.camel.CamelException in the Exception field to handle the exceptions.

  11. Double-click the cProcessor component to display its Basic settings view in the Component tab.

  12. Customize the code in the Code area to show the message body:

    System.out.println(exchange.getIn());

  13. Press Ctrl+S to save your Route.

Executing the Route

Click the Run view to display it and click the Run button to launch the execution of your Route. You can also press F6 to execute it.

The message Hello! is sent from the Route to the Job and caught as exception: