O'Reilly logo

Java Enterprise in a Nutshell, Third Edition by William Crawford, Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 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. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required