Message acknowledgement or transacted session? Posted on 05/30/2011,
No Comments (ADD)
JMS is one of the oldest Java EE specifications (JMS 1.0 specification is dated 11/1999), however, questions about
The difference between message acknowledgement and transacted session still come up. The difference is especially subtle when programmatic client acknowledgement (Session.CLIENT_ACKNOWLEDGE
) Is used since
Message.acknowledge()
AndSession.recover()
Are similar
Session.commit()
AndSession.rollback()
. So how are these
APIS different?
The bottom line is that there is no difference if you deal only with a single resource (queue or topic) within a session. if all you do is consuming messages from a single queue, it does not matter whether you use acknowledgements or transacted sessions
(Although in my opinion it is more intuitive to use session. Commit/rollback ).
Session.commit()
InvokesMessage.acknowledge()
Under the covers and
Session.rollback()
Invokesrecover()
.
However, if you're dealing with multiple JMS resources withing the same session (or multiple consumers/producers), The transacted session mechanic is what you want to use. for example, you may consume messages from one queue and
Then put messages on a different queue using the same JMS
Session. the transacted session will treat all consumed and produced messages as part of a single transaction and will commit or rollback all messages at once. message acknowledgement on a non-transacted session will "commit" consumed messages independently
Of the produced ones.
Transacted sessions are limited to JMS resources; container-managed transactions and
JTA is required to managed JMS
And non-JMS resources (e.g., getting a message from a queue and updating a database ).
As a summary, the different mechanic ISMs discussed here differ in terms of the types of resources managed as part of transactions:
- Message Acknowledgement: messages consumed from a single destination.
- Transacted session: Multiple JMS resources within the same
JMS session.
- Container-managed transactions: Multiple JMS and non-JMS resources.
For a more in-depth discussion of different transaction mechanisms, refer
This article.
From:
Http://myarch.com/message-acknowledgement-or-transacted-session