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 7-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 7-8. Transactional messages are sent in an all-or-nothing fashion

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

Get Java Message Service, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.