JMS Messaging with Transactions

Version: 17.01

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 transaction 1

Implementation

In-order to develop the above mentioned flow, first you need to add Spring JMS from connector list and regular-transform dependency from processors 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.

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.

After that, in the project.xpml file select the ActiveMQ JMS template and fill the necessary fields. After that following resources will be added to the project.xpml file

jms transaction 2

In-order to develop the flow, first let’s create an integration flow named “main-jms-integration” and follow the below steps

  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.

jms transaction 3
  1. Insert a Transaction scope start element to transactionally process the obtained message

  2. 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.

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

jms transaction 5
  1. 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

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

jms transaction 7
  1. In the cloned message path add another egress connector to send the JSON message to audit destination

jms transaction 8
  1. Add a Logger processing element to log the XSD validation failure and specify its properties as below.

jms transaction 9
  1. After that add an Exception flow end element to exceptionally complete the flow

The complete flow should look as below

jms transaction 10

Now after running the project, send the sample message to the source queue and it will be sent to the both destination queue.

{
  "Currency" : "LKR",
  "BookingReference" : "bkp-23-er",
  "BookingDepartureDate" : "2017-02-23",
  "ItemCity" : "BER",
  "Item" : "GER",
  "CheckInDate" : "2017-02-25",
  "CheckOutDate" : "2017-03-12",
  "hotelRooms" : 3,
  "ID" : "002:BER:GER:123:456:234"
}

If you remove or change any field, then the XSD validation will fail and message will be rolled back to the original queue without sending it to either of destination queues.

Property Configuration

When running the sample in the UltraESB-X distribution, you need to override the following properties in-order for the sample to work.

Refer to Managing Project Properties documentation on how to override properties.

SpringJMSIngressConnector.jmsListener.queueName

The name of the source queue

SpringJMSEgressConnector.springSender.destination

The name of the destination queue

SpringJMSEgressConnector.auditSender.destination

The name of the audit queue

activeMq.brokerURL

Active MQ broker URL (e.g: tcp://localhost:61616)

In this topic
In this topic
Contact Us