How to create a mediation route Learn how to create a simple route

In this tutorial, we will see how to create two simple routes:
-One that will read JMS messages from a queue, send the payload of these messages as requests to a data service and send the responses to another queue.
-One that will read the responses from the latter queue and send them to the standard output.

To do this, we will provide you with the needed Greeting service: a service to which you send a name (for example: Talend) and send a response saying "Hello" with the name sent as a request (for example: Hello Talend).

Prerequisites:
To follow this tutorial, Talend Open Studio for ESB or Talend Enterprise ESB Studio and Talend Runtime should already be installed and running.
You also need to download and extract the exampleFile.zip file available at the bottom of this page, in the Download it! section of this tutorial.
Once unzipped, you will get a GreetingService.zip file. This file holds the Greeting Service and Jobs to import in the Studio to be able to follow this tutorial.
To import the Service and Jobs, click the Import items button from the Studio, select the GreetingService.zip in the Select archive file field and select all the items.
Once imported, you will need to deploy the service by yourself as shown in the "Export and deploy a service in Talend Runtime" section of the [How to deploy a service in Talend Runtime] tutorial.

Download it!

You want to practice?

Download exampleFile.zip to get the files used for this tutorial.

You can also download tutorialProject.zip containing all the jobs needed to carry out this tutorial.

You can also:
Send it!

Share it!

 


Test the service provided


In Talend Runtime:

To check if the Greeting service is correctly deployed and running, type in the following command: cxf:list-endpoints.

The Greeting service displays as Started at the /GreetingService Address.

Next
To check whether the service is available, you can also go to the CXF service list located at: http://localhost:8040/services.

In this page, the GreetingService service operation is listed and information like the endpoint address and a link to the WSDL are provided.

The endpoint address and the WSDL URI will be reused later on in this tutorial, to access the service endpoint and WSDL via the mediation components.

Next
You can test it with the consumer Job provided with the service, as prerequisite. This job sends "Talend" to the service to get "Hello Talend" message as a response.

In the Repository view of the Studio:

Expand the Job Designs node and double-click the GreetingServiceConsumer Job to open it on the Designer.

Press F6 to run the Job.
The Run view displays at the bottom of the Studio and the console follows the execution. The "Hello Talend" response message displays.

Next
Launch a message broker


The route we will build will read JMS messages from one queue, send the payload of these messages to the data service running in the container and the responses will be send back to another queue.

To do so, you have to run a message broker. Talend Runtime is providing the Apache ActiveMQ message broker in the following directory \Runtime_ESBSE\activemq.

However ActiveMQ needs to be started from the commandline, so copy the path to the bin directory holding the activemq.bat executable file.

Next
Open a commandline window and browse to ActiveMQ's bin directory, here we used the command: cd C:\Talend\501\Runtime_ESBSE\activemq\bin and press Enter.

From the C:\Talend\501\Runtime_ESBSE\activemq\bin> prompt, type in activemq.bat and press Enter.

Active MQ is started.

Next
To check whether the ActiveMQ is running, go to its Web console at the following URI: http://localhost:8161/admin.

Click the Queues menu to access the list of queues available.

An example of queue is available by default in the list. Click Delete to remove it.

Next
Create the route connecting to the input and output queues


To create a route, click the Mediation button at the top right hand corner of the Studio's main window to switch to the Mediation perspective.

In the Repository view of the Mediation perspective:

Right-click Routes.

In the menu, click Create Route to open the New Route wizard.

Next
In the New Route wizard:

In the Name field, name the route JMStoHTTP.

Click Finish to close the wizard and create the Route.

The Route Designer opens an empty Route.

Next


In the Name field, accents, special characters and spaces are invalid. Also do not use numbers to start the field.

In the Palette to the right:

To add the two JMS components that will communicate with ActiveMQ, click the Messaging component family.

Click the cJMS component and drop it onto the Route Designer to the left of the canvas. Repeat this step to add the second cJMS component to the right of the canvas.

Next
On the same Messaging family, click the cCXF component and drop it onto the Designer between the two cJMS components.

The cCxf mediation component will be used to access the Greetings service.

Next
On the Route Designer:

Double-click the first cJMS component to display its corresponding Component view and set its properties.

In the Component view:

In the Destination field, name the input queue "IN".

In the Broker URI field, type in ActiveMQ's default URI of the localhost server: "tcp://localhost:61616".

Next
On the Route Designer:

Double-click the second cJMS component to display its corresponding Component view and set its properties.

In the Component view:

In the Destination field, name the output queue "OUT".

In the Broker URI field, type in the same URI: "tcp://localhost:61616".

Next
Double-click the cCXF component to display its corresponding Component view and set its properties.

In the Component view:


In the Address field, type in the endpoint URL of the service deployed on Talend Runtime: http://localhost:8040/services/GreetingService.

In the WSDL File field, type in the URL of the corresponding WSDL: http://localhost:8040/services/GreetingService?wsdl.

In the Dataformat list, select PAYLOAD as we will only work with the payload (message body) of the message; we are only sending a payload to the JMS.

Next
On the Route Designer:

To link the components together, right-click the first cJMS component, select Row > Route in the menu and click the cCXF component.

And right-click the first cCXF component, select Row > Route in the menu and click the second cJMS component.

Next
In the Route Designer:

Press F6 to run the Route.
The Route is automatically saved before being executed.

The Run view displays at the bottom of the Studio and the console follows the execution. We can see that the CXF component is connecting to the service endpoint.

Next
Now, if we go back to the ActiveMQ Web console, we can see the IN incoming queue is already created.

So, we are going to put some data inside this queue. To do so:

Click the Send To link available in the Operations column of the IN queue.

Next
In the Send a JMS Message form of our IN queue:

In the Message body field, type in the payload to be send:
<tns:greetRequest xmlns:tns="http://www.talend.org/service/"><in>Talend</in></tns:greetRequest>
Here, we are sending a "Talend" data to the IN queue.

Click the Send button.

Next
In the Studio, we can see that one message has been processed.

The JMS reads it out, sends it to the CXF service, the service got called and then the response is sent to another queue.

To see this other queue, go back to the ActiveMQ Web console.

Next
In the ActiveMQ Web console:

Click the Queues link in the navigation menu to refresh the Queues page.

Our OUT output queue has been created and it has one message inside it.

To check the outgoing queue, we will build another route from the studio.

Next
Create the route reading the output queue


In the Repository:

Right-click Routes.

In the menu, click Create Route to open the New Route wizard.

Next
In the New Route wizard:

In the Name field, name the route ConsumerJMS.

Click Finish to close the wizard and create the Route.

The Route Designer opens an empty Route.
Next


In the Name field, accents, special characters and spaces are invalid. Also do not use numbers to start the field.

In the Palette to the right:

To add the JMS component that will communicate with ActiveMQ output queue, click the Messaging component family.

Click the cJMS component and drop it onto the Route Designer to the left of the canvas.

Next
On the same Messaging family, click the cMessagingEndpoint component and drop it onto the Designer next to the cJMS component.

Next
On the Route Designer:

To link the components together, right-click the cJMS component, select Row > Route in the menu and click the cMessagingEndpoint component.

Next
On the Route Designer:

Double-click the cJMS component to display its corresponding Component view and set its properties.

In the Component view:

Fill in the connection information to the OUT queue.

In the Destination field, name the output queue "OUT".

In the Broker URI field, type in the URI of the localhost server: "tcp://localhost:61616".

Next
Double-click the cMessagingEndpoint component to display its corresponding Component view and set its properties.

In the Component view:

In the URI field, type in "log:OUT" to print the message of the OUT queue to the Standard output.

Next
In the Route Designer:

Press F6 to run the Route.
The Route is automatically saved before being executed.

The Run view displays at the bottom of the Studio and the console follows the execution. We can see that "Hello Talend" has been received.

Click the Kill button to stop the route.

Next
Let's try to send another payload to the IN queue. To do so:

Go back to the Send a JMS Message form of the IN queue:

In the Message body field, type in the payload to be send:
<tns:greetRequest xmlns:tns="http://www.talend.org/service/"><in>ESB</in></tns:greetRequest>
Here, we are sending an "ESB" data to the IN queue.

Click the Send button.

Next
In the Studio, press F6 again to start the consumer route.

The Hello ESB message has been received.

Next
And if you have a look at the JMStoHTTP Route, two messages have been processed: Hello Talend and Hello ESB.


 

    Download it!     Send it!     Share it!

You want to practice?

Download exampleFile.zip to get the files used for this tutorial.

You can also download tutorialProject.zip containing all the jobs needed to carry out this tutorial.

Friends / colleagues may be interested in this tutorial? Send it to them!

You liked this tutorial ? Support it!

[ top ]