Transacted messages are a group of messages that form a single unit of work. Much like an accounting transaction made up of a set of balancing entries, a messaging example might be a set of financial statistics where each entry is a completely formed message and the full set of data comprises the update.
A session is declared as transacted when the session is created. While producers—PTP Senders and Pub/Sub Publishers—produce messages as usual, the messages are stored at the broker until the broker is notified to act on the transaction by delivering or deleting the messages. To determine when the transaction is complete, the programmer must:
Call the method to commit the set of messages. The session's
commit()method tells the broker to sequentially release each of the messages that have been cached since the last transaction. In this sample, the commit case is set for the stringCOMMIT.Call the method to roll back the set of messages. The session's
rollback()method tells the broker to flush all the messages that have been cached since the last transaction ended. In this sample, the rollback case is set for the stringCANCEL.
To run the Pub/Sub TransactedChat samples do the following:
In window 1, enter
ant chat1.In window 2, enter
ant xnchat.In the
TransactedChatterwindow, type some text and press Enter.Type
COMMITin theTransactedChatterwindow and press Enter.The message is delivered to the
TransactedChatterwindow and to theChatter_1window.Type text in the
TransactedChatterwindow and press Enter.Repeat to produce a few messages.
Type
COMMITin theTransactedChatterwindow and press Enter.The batch of messages is delivered as a series of individual messages to the
TransactedChatterwindow and to theChatter_1window.Type text in the
TransactedChatterwindow and press Enter.Repeat to produce a few messages.
Type
CANCELin theTransactedChatterwindow and press Enter.The batch of messages is dropped.
Subsequent entries will form a new transaction to either commit or rollback.








