Red Hat DocumentationFuse Message BrokerToggle FramesPrintFeedback

TransactedChat Application

What that sample shows

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 string COMMIT.

  • 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 string CANCEL.

Running the sample

To run the Pub/Sub TransactedChat samples do the following:

  1. In window 1, enter ant chat1.

  2. In window 2, enter ant xnchat.

  3. In the TransactedChatter window, type some text and press Enter.

  4. Type COMMIT in the TransactedChatter window and press Enter.

    The message is delivered to the TransactedChatter window and to the Chatter_1 window.

  5. Type text in the TransactedChatter window and press Enter.

  6. Repeat to produce a few messages.

  7. Type COMMIT in the TransactedChatter window and press Enter.

    The batch of messages is delivered as a series of individual messages to the TransactedChatter window and to the Chatter_1 window.

  8. Type text in the TransactedChatter window and press Enter.

  9. Repeat to produce a few messages.

  10. Type CANCEL in the TransactedChatter window and press Enter.

    The batch of messages is dropped.

Subsequent entries will form a new transaction to either commit or rollback.

Stopping the sample

To stop all the applications, press Ctrl+C in each of the windows.

Comments powered by Disqus