Transacted Messages

Our discussion of message acknowledgment shows that producers and consumers have different perspectives on the messages they exchange. The producer has a contract with the message server that ensures the message will be delivered as far as the server. The server has a contract with the consumer that ensures the message will be delivered to it. The two operations are separate, which is a key benefit of asynchronous messaging. It is the role of the JMS provider to ensure that messages get to where they are supposed to go. Having all producers and all consumers participate in one global transaction would defeat the purpose of using a loosely coupled asynchronous messaging environment.

JMS transactions follow the convention of separating the send operations from the receive operations. Figure 6.8 shows a transactional send, in which a group of messages are guaranteed to get to the message server, or none of them will. From the sender's perspective, the messages are cached by the JMS provider until a commit( ) is issued. If a failure occurs, or a rollback( ) is issued, the messages are discarded. Messages delivered to the message server in a transaction are not forwarded to the consumers until the producer commits the transaction.

Transactional messages are sent in an all-or-nothing fashion

Figure 6.8. Transactional messages are sent in an all-or-nothing fashion

The JMS provider will not start delivery of the messages to its ...

Get Java Message Service now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.