Broker 10.5 | webMethods Broker Documentation | webMethods Broker Messaging Programmer's Guide | Coding Messaging Client Applications | C# Messaging Clients | 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, AcknowledgeMode.Auto);
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).
session.Commit();
When the transaction commits, the inbound (request) message is acknowledged and removed from the 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.