This section provides a scenario to illustrate how to create a Route using the data service we created in the previous section.
In this scenario, we will define a Route using the Web service we just created, send a request to this Web service and retrieve the response from the Web service for a further use.
To send data to request the Web service, we use Apache ActiveMQ as the message broker. We need to launch the ActiveMQ server before executing the Route. For more information about installing and launching ActiveMQ server, see the Talend Installation Guide and the Apache Web site http://activemq.apache.org/index.html.
To create the Route, we need a cJMSConnectionFactory component to specify the connection factory for message handling, two cJMS components, one to read a JMS message from one queue and send the request to the Web service and the other to retrieve the response from the Web service and save it in another queue, and a cCXF component to connect to the Web service.
To create the Route, proceed as follows:
On the Repository tree view, right-click the Route node and from the contextual menu, select Create Route.
In the pop-up wizard, enter the information corresponding to the fields you need to complete. In this scenario, enter airportRoute in the Name field and click Finish. The Route is opened in the design workspace.
From the Palette, drop a cMQConnectionFactory, a cCXF, a cProcessor, and two cJMS components on to the design workspace.
Label the components for better identification of their roles and link them using the Row>Route connection as shown below.
Double-click the cMQConnectionFactory component to display its Basic settings view in the Component tab.
From the MQ Server list, select ActiveMQ.
In the Broker URI field, type in the URI of the local ActiveMQ server,
"tcp://localhost:61616"in this use case.
Double-click the cJMS component labeled Input to display its Basic settings view.
From the Type list, select queue to send the messages to a JMS queue.
In the Destination field, type in a name for the JMS queue,
"IN"in this use case.
Double-click the [...] button next to ConnectionFactory. Select the JMS connection factory that you have just configured in the dialog box and click OK. You can also enter the name of the cMQConnectionFactory component directly in the field.
Repeat this operation to configure the cJMS component labeled Output with the same ConnectionFactory and name the destination JMS queue OUT.
Double-click the cCXF component to display its Basic settings view.
In the Address field, type in the service endpoint URL of the Web service that we have created,
http://localhost:8200/airport.servicein this example.
From the Type list, select wsdlURL.
In the WSDL File field, type in the path to the WSDL file,
http://localhost:8200/airport.service?wsdlin this example.
From the Dataformat list, select PAYLOAD.
Double-click the cProcessor component to display its Basic settings view.
In the Code area, customize the code as shown below to display the message body on the Run console.
System.out.println("The output message is: "+ exchange.getIn().getBody(String.class));
Click the Run view to display it and click the Run button to launch the execution of the Route. You can also press F6 to execute it.
RESULT: The Route is successfully started.
Switch to the ActiveMQ Web console. The incoming queue is already created.
Enter the message body as shown below in the incoming queue and send the message.
In the Route designer, we can see that the message payload is sent to the Web service. The Web service get called and the response is sent to another queue, OUT as we have configured.