Broker 10.5 | webMethods Broker Documentation | webMethods Broker Messaging Programmer's Guide | Coding Messaging Client Applications | JMS Request-Reply Application with a Message Selector | Application Code | Implementing a Local Transaction
Implementing a Local Transaction
The example contains a local transaction consisting of the following elements:
*Receipt of a customer inquiry message
*Acknowledgment of the customer inquiry message
*Publishing of a reply
The code for setting up the local transaction is in the server application, and is shown below:
session = conn.createSession(true, 0);
sender = session.createProducer(null);
receiver = session.createConsumer(destination);
Here, a session is created transactionally by setting the first parameter in conn.createSession() to a value of true. Since the message sender and the message receiver are both created from the same session, they share the same transactional context.
The transaction is executed in onMessage(). There, a session.commit() is issued, which means that if the local transaction is successful, receipt of the original message is acknowledged (because the message consumer is part of the transaction) and the reply is published (because the message producer is part of the transaction).
When the transaction commits, the inbound (request) message is acknowledged and removed from the JMS message queue, and the outbound (reply) message is published. If the transaction cannot commit and is rolled back, the inbound message is returned to the message queue and no message acknowledgment or publishing takes place.
JMS transactions of a larger scope, such as those that include operations on databases, must be implemented in the context of a distributed transaction, using the JMS XA interfaces and a distributed transaction manager. For more information, see Java Transaction API Support (JMS Clients Only).