Java Reference
In-Depth Information
Transaction and acknowledgment modes
In order to control the overall performance and reliability of an asynchronous messaging
system, we need to take two factors into account: persisting of messages and acknowledg-
ment. Let's take a look at those characteristics.
Reliability of the system is focused on the ability to deliver messages exactly once. This
means that no message is lost, and there are no duplicates. For most systems, it is a strong
requirement that you don't miss or duplicate any orders (like in an e-commerce site).
However, usually it is not a problem to miss an update from the stock market because a
newer one would overwrite it in a moment. Of course, additional features such as reliability
come at a price, and in the case of JMS, the price is paid in performance. The more reliable
the system, the lower its message throughput is.
When a message is processed, it can be held only in the memory or persisted somewhere
on the disk. Messages stored in the memory are lost in the case of a failure or when the
messaging service is stopped. Persisted messages can be retrieved from the disk after the
service is restarted and therefore delivered to the consumers at least once (but still without
any guarantees about the acknowledgment). Without this mechanism, messages can poten-
tially be lost in the system because a failure might occur before they are delivered.
However, the overhead of storing them can have a serious impact on the system's perform-
ance characteristics.
Acknowledgment is important to inform the JMS service that the message was really re-
ceived and processed by the consumer. Different levels of acknowledgments can be used to
avoid duplicates or to trigger JMS to send the message once more, possibly to another con-
sumer. A JMS provider will ensure that an acknowledged message is delivered only once.
The application is responsible for properly handling rolled back messages that were rede-
livered (such messages are marked with the JMSRedelivered header).
If the consumer session is handled in a transaction, then the messages are acknowledged
only when the transaction is committed. However, there is an option to disable transaction-
al message-driven beans and manually handle the acknowledgment. In this case, there are
the following three types of acknowledgement options:
AUTO_ACKNOWLEDGE : With this, the consumed messages are being ac-
knowledged automatically
Search WWH ::

Custom Search