JMS Messaging with Transactions

Version: 17.07

Supported Since: 17.01

Use Case Description

The Umbriel Travels Ltd. is a travel agency which arranges accommodations for tourists in South Asia region. The Umbriel Travels exposes an online portal for their customers to book hotels and these booking details are sent to a backend JMS queue from the online portal in a JSON format.

The actual legacy booking services in the backend only accepts XML format messages and emits confirmation messages in XML format as well. Umbriel Travels wants to convert the received JSON messages into XML and vice versa without loosing any messages in between.

Further, they want to send the original JSON message to a another JMS queue for auditing purpose.

Proposed Solution

Umbriel Travels has decided to integrate the backend booking server through an ESB and delegate the message transformation logic to the ESB. Following diagram depicts the overall architecture of the design. In-order to guarantee that there is no message loss, due to errors in message transformation, JMS transactions have been used. For this implementation, they have decided to use ActiveMQ as the JMS provider.

jms transactions jms transaction 1

UltraStudio Configuration

UltraESB-X Configuration

Implementation of the Solution

Prerequisite

In order to implement above use case you must first select following dependencies when you are creating a new Ultra project.

  • Spring JMS Connector from the connector list

  • Message Transformer, Flow Control, XML Operations, Logging from the processor list

If you have already created a project, you can add above dependencies via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Connectors list and Processors list, select above dependencies.

For this sample let’s use ActiveMQ and if you have not already installed ActiveMQ please follow the installation guide.

First open the project.xpml file of the project and right click on it (on the XML content of the file). From the context menu, select Resource Template as shown in below figure

jms transactions jms egress connector 5

After that from the shown dialog box, select ActiveMQ JMS template.

jms transactions jms egress connector 6

Next you need to specify the required parameters as shown below. It is mandatory to specify a bean prefix and for that you can specify any value. The only other mandatory field is the ActiveMQ Broker URL.

jms transactions jms egress connector 7
You need to add activemq-all jar into the lib directory of the project. Further, when deploying the project in the UltraESB-X, you need to add the activemq-all jar into the lib/custom directory as well.
Implementation

To implement above use case, first create an integration flow named “jms-transaction-flow”, and then add required components by going through following steps in order.

  1. Add a JMS Ingress Connector to obtain the request messages in the JMS Format from the source queue. For the connection factory select activeMq-SpringCachingConnectionFactory. Under Transaction tab, select activeMq-ultraTxnmanager as the transaction manager.

  2. Insert a Transaction Scope Start Element to transactionally process the obtained message

  3. Add a Clone Message Processor to clone the received message. For the Exchange pattern specify Keep Original, completion procedure should be On completion of both and specify With full message as the clone type.

  4. In the original Message Path, add a JSON to XML Transformer and under root element name specify AddBookingRequest

  5. Next, add a XSD Validator to validate the transformed XML message and select the addBooking.xsd file (in src/resources directory) as the XSD file path

  6. After that send the validated message to destination JMS queue using a JMS Egress Connector. Specify ActiveMq-jmsTemplate as the JMS template and the destination queue name as well.

  7. In the cloned message path add another JMS Egress Connector to send the JSON message to audit destination

  8. Add a Logger Processing Element to log the XSD validation failure and specify its properties as below.

  9. After that add an Exception Flow End element to exceptionally complete the flow

The completed integration flow should look like below.