Transactions

As you may know, transactions are sets of indivisible operations that either succeed or roll back. Transactions in a messaging system are used to group the messages logically. When we send a group of messages in a transaction to a queue or topic, we either commit them or we roll them back. This means that the messages are either all delivered in one go or they are rolled back. On the consumer or receiver side, the messages are all either consumed and acknowledged or rolled back.

Let's take a closer look. When messages are sent in a transaction, the messages are not sent to the messaging provider, in our case the GlassFish server queue/topic, until we invoke the commit() function on the jmsContext as shown in the following diagram:

On the consuming side, when transactions are enabled, the messages will be removed from the queue or topic only when they are committed or rolled back. Until the commit() function is called, the message stays in the messaging provider service. This is shown in the following diagram:

Let's take a look at some code to understand these concepts further. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset