Talend Tips: Trigger a Job using Socket Listener

We talked about triggering a Talend job by using file listener previously. Today, let’s proceed to the next component which is the tWaitForSocket.


This component utilizes the ServerSocket object in Java to act as a server to listen to a port and trigger the integration process if there is an activity. As you can see in Figure 1, this component does not have much configuration if compares to the tWaitForFile component. You just need to specify the following:

  1. port to listen on
  2. response message for client
  3. action whether to continue listening on the port or close the socket


Figure 1: tWaitForSocket


Once the configuration is done, you can run the job to have it start listening on the port that you have specified. To test the configuration, you can create a simple Java client as shown:


import java.io.*;
import java.net.*;

public class TestConnection {

    public static void main( String [] args ) throws IOException {

 DataOutputStream dos = null;
 BufferedReader in = null;

        int timeout = 2000; // two seconds       

        String host = args[0];
        String port = args[1];
 String data = args[2];

        System.out.printf("Triggering Talend job: %s port: %s ....\n", host, port );

        Socket socket = new Socket();
        InetSocketAddress endPoint = new InetSocketAddress( host, Integer.parseInt( port )  );

        try { 

 socket.connect(endPoint , timeout);
 System.out.printf("Success: %s  \n",  endPoint );

 dos = new DataOutputStream(socket.getOutputStream());

 in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
 System.out.println("Response from Talend: " + in.readLine());

        } catch( IOException ioe ) {

            System.out.printf("Failure: %s message: %s - %s \n", endPoint , ioe.getClass().getSimpleName(),  ioe.getMessage());

        } finally {




Important note:

This component is useful if you want to trigger a Talend job remotely, however, it does not take or process the data that send to the socket.