Transactional Messaging
JMS supports transactional messaging
in two ways. In its simplest form, a Session
is
created with the transactional option (the first argument to
QueueConnection.createQueueSession( )
and
TopicConnection.createTopicSession( )
).
QueueSession xactSession = qConn.createQueueSession(TRUE, Session.AUTO_ACKNOWLEDGE);
When using a transactional Session
, the client
performs a series of “transactions”
with the Session
(sends and/or receives messages
from consumers and producers associated with the
Session
). These sends and receives are either
committed by calling the Session's
commit( )
method, or cancelled by calling
rollback( )
. If a Session
is
committed, all of the sends and receives are committed to the JMS
provider, which causes the new state of the
Destination
(s) affected to be committed. If a
Session
is rolled back, all changes to the
resources on the JMS provider are rolled back. In either case, the
transaction is closed and a new one is started automatically, for any
subsequent messaging actions.
JMS providers can also support
transactional messaging through the Java Transaction API (JTA),
which allows messaging transactions to be integrated with other
resources, like databases. These JTA-based transactions are
distributed: the underlying transactional resources can be
distributed across the enterprise. The JMS API supports this form of
transactional messaging with a set of interfaces that provide access
to JTA-aware Connections
and
Sessions
. If a JMS provider ...
Get Java Enterprise in a Nutshell, Second 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.