Skip to main content Skip to complementary content

Route communicating with data integration Job

This section provides a scenario of how to use the Camel components not included in the palette in a Route and to use sockets for connecting a Job and a Route.

In this scenario, you will create a data integration Job that listens messages from one socket port and sends out the messages to another port. Then you will create a Route that sends a test message to the listening port and logs message changes of the incoming and outcoming ports.

Creating a data integration Job

Procedure

  1. From the Integration perspective of the Talend Studio , create a Job and open it in the design workspace.
    For more information on how to create a Job, see Creating a Job.
  2. From the palette, place a tSocketInput, a tSocketOutput, and a tLogRow component onto the design workspace. Link them together with the Row > Main connection.
    Screenshot of the Job in the design workspace.
  3. Double-click the tSocketInput component to open its Basic settings view in the Component tab.
    Basic settings view.
  4. Define the listening Port number in the Port field, 8900 for example. By default, the local host server is used. Set the amount of time (in seconds) to 30000 in the Timeout field, after which the Job will time out.
  5. Double-click the tSocketOutput component to open its Basic settings view in the Component tab.
    Basic settings view.
    Basic settings view.
  6. Enter your host IP address and your port number in the Host and Port fields.
    The tLogRow component is used to monitor data processed and does not need any configuration.
  7. Press Ctrl+S to save your Job.

Creating a Route to communicate with the Job

Procedure

  1. Create a Route and open it in the design workspace.
    For more information on how to create a Route, see Creating a Route.
  2. From the palette, place a cSetBody, and five cMessagingEndpoint components onto the design workspace. Label the components for better identification of their roles and link them together with the Row > Main connection.
    Screenshot of the Job in the design workspace.

Configuring the incoming sub-route

Procedure

  1. Double-click the testMina component to open its Basic settings view in the Component tab.
    Basic settings view.
  2. In the URI field, enter the code "timer:testOneWayMina?delay=1000&period=2000" to define a timer for starting message exchanges. In this use case, we want each message to be delivered after a 1-second delay at a period of 2 seconds.
  3. Double-click the initializeRequest component to open its Basic settings view in the Component tab.
    Basic settings view.
  4. Select Constant from the Language list box and type in "test message\n" in the Expression field.
  5. Double-click the logRequest component to open its Basic settings view in the Component tab.
    Basic settings view.
  6. In the URI field, enter "log:jobSocketIn" where the incoming message exchanges are logged.
  7. Double-click the jobSocketIn component and click Advanced settings view in the Component tab.
    Advanced settings view.
  8. In this use case, use the Camel component camel-mina as the transport. To use this component, click Add at the bottom of the Dependencies list to add a row and select mina from the drop-down list. For more information about Mina, see the Camel Apache documentation.
    Alternatively, you can use a cConfig component and add the library of MINA to the Dependencies list of the cConfig component. To do so, click Add at the bottom of the Dependencies list to add a row. Select this row and click the [...] button at the end to show the Select Module wizard.
    Basic settings view.
    Select camel-mina-alldep-2.9.2.jar from the inner modules and click OK to add it to the Dependencies list.
    Select Module wizard.
  9. Click the Basic settings view in the Component tab of the jobSocketIn component. In the URI field, enter "mina:tcp://localhost:" + 8900 + "?textline=true&sync=false" to send the message to the Mina endpoint of a TCP service on port 8900 as a text line in the InOnly mode.
    Basic settings view.

Configuring the outcoming sub-route

Procedure

  1. Double-click the jobSocketOut component to open its Basic settings view in the Component tab.
    Basic settings view.
  2. In the URI field, enter "mina:tcp://localhost:" + 8901 + "?textline=true&sync=false" of the outcoming socket port.
  3. Double-click the logResponse component to open its Basic settings view in the Component tab.
    Basic settings view.
  4. In the URI field, enter "log:jobSocketOut" where the outcoming message exchanges are logged.
  5. Press Ctrl+S to save your Route.

Viewing the code and executing the Route and the Job

Procedure

  1. Click the Code tab at the bottom of the design workspace to check the generated code.
    Generated code in the Code tab.

    As shown above, the message flow from testMina is given a payload by cSetBody and then sent to logRequest and jobSocketIn. The other message flow is sent from jobSocketOut to logResponse.

  2. Press F6 to execute the Route, and then run the Job in the same way. The Route will keep trying to connect to the defined ports until the Job starts.

    The message change log of the incoming and outcoming ports is printed in the execution console of the Route.

    Execution console of the Route.

    On the Job side, the message processed is also displayed in the console.

    Execution console of the Job.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!