JMS supports transactional messaging in two ways. In its simplest form, a
Session is created with the transactional
option (the first argument to
QueueSession xactSession = qConn.createQueueSession(TRUE, Session.AUTO_ACKNOWLEDGE);
When using a transactional
Session, the client performs a series of
“transactions” with the
(sends or receives messages from consumers and producers associated
Session). These sends and
receives are either committed by calling the
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
Destination(s) affected to
be committed. If a
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. For broader coverage of JTA in a variety of contexts, see Chapter 16. The following material highlights some transactional details specific to JMS messaging.
JTA-based transactions are distributed: the underlying transactional resources can be distributed across the enterprise. The JMS ...