Transaction and redelivery in JMS
Make the right transaction decision for your message delivery
By Prakash Malani, JavaWorld.com, 02/15/02
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Architecting and designing applications with the Java Message Service (JMS) requires not only knowing how to use the JMS API,
but also having a solid foundation of its concepts. This article focuses on two such powerful concepts: transaction and redelivery. In JMS, a transaction organizes a message or message group into an atomic processing unit; failure to deliver a message
may result in redelivery of that message or message group.
In this article, I help you develop a thorough understanding of your transaction options and show how you can evaluate their
impact on message redelivery. I assume you have some familiarity with the JMS API as well as message-driven beans (MDBs).
Transaction option overview
An application has myriad transaction options available, including whether or not it wants to participate in transactions.
If your application does not use transactions, it can use one of these acknowledgement modes: auto, duplicates okay, and client.
You specify the acknowledgement modes when creating a JMS session. If your application uses transactions, it can choose from
these transaction options: transacted session, MDB with container-managed transaction demarcation (CMTD), and MDB with bean-managed
transaction demarcation (BMTD). The following lists briefly describe these acknowledgement modes and transaction options.
Acknowledgement options:
- Auto mode: When a session uses auto mode, the messages sent or received from the session are automatically acknowledged. This is the
simplest mode and expresses JMS's power by enabling once-only message delivery guarantee.
- Duplicates okay mode: When a session uses duplicates okay mode, the messages sent or received from the session are automatically acknowledged just
like auto mode, albeit lazily. Under rare circumstances, the messages might be delivered more than once. This mode enables
at-least-once message delivery guarantee.
- Client mode: When a session uses client mode, the messages sent or received from the session are not acknowledged automatically. The application
must acknowledge the message receipt. This mode gives the application (rather than the JMS provider) complete control over
message acknowledgement, at the cost of increased code complexity.
Other types of acknowledgement modes are possible. However, these acknowledgement modes are JMS provider specific, and therefore,
compromise the JMS application portability.
Transaction options:
- Transacted session: An application can participate in a transaction by creating a transacted session (or local transaction). The application
completely controls the message delivery by either committing or rolling back the session.
- Message-driven beans with CMTD: An MDB can participate in a container transaction by specifying CMTD in the XML deployment descriptor. The transaction commits
upon successful message processing or the application can explicitly roll it back.
- Message-driven beans with BMTD: An MDB can choose not to participate in a container transaction by specifying BMTD in the XML deployment descriptor. The
MDB programmer has to design and code programmatic transactions.
Figure 1 depicts a decision tree of the previously mentioned transaction options.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Great articleBy Anonymous on September 16, 2009, 11:05 amIf i had to explain JMS to anyone i would recommend reading this first to them. Great article. thanks
Reply | Read entire comment
Specific and clearBy Anonymous on May 21, 2009, 2:25 pmThanks. Made my life easier. so clear and understandable.
Reply | Read entire comment
Really appreciate yourBy Anonymous on March 6, 2009, 3:40 pmReally appreciate your article, so clear and well written.
Reply | Read entire comment
For a CMTD MDB, "The transaction commits upon successful return from the onMessage() method...By Anonymous on November 30, 2008, 10:37 amFor a CMTD MDB, "The transaction commits upon successful return from the onMessage() method." Catching the exception within onMessage() method would always make...
Reply | Read entire comment
View all comments