
What are the different types of transactional options available in JMS?
JMS offers two transactional options: transacted sessions and an integration with the WebLogic Server's Java Transaction API (JTA) transaction service. Transacted sessions are used when transactional behavior is required within a single JMS session.
How do I run a local transaction in JMS?
JMS applications can run local transactions by first creating a transacted session. An application can commit or roll back a transaction. JMS applications can run local transactions. A local transaction is a transaction that involves changes only to the resources of the queue manager to which the application is connected.
What happens to JMS messages when a transaction is committed?
When the transaction commits, any JMS messages produced within the transaction are enabled for delivery. Any received messages will be acknowledged with a commit. A transaction abort will release any sent messages while received messages will be returned to their JMS destination and redelivered.
What is the difference between associated transactions and transactional sessions?
When the associated transaction is committed, the JMS implementation acknowledges all messages received in the associated transaction. If the transaction aborts, the JMS implementation returns the messages to the associated queue or topic. Transacted sessions are used when transactional behavior is required within a single JMS session.

What is JMS session?
A JMS Session is a 'single-threaded context', so each thread must use a different session. In contrast, a JMS connection can be shared between multiple threads. Also, one thread could own multiple sessions. The send/receive operations on a Session are either acknowledged or transacted.
What is Transactionsgroup send or receive?
Transactionsgroup send or receive operations on that session (all-or-nothing). So you do send/send/send and then commit and know all 3 msgs are made available to the consumer at the time of the commit, or none. Advantages of transacted delivery: highest guarantee of delivery and you can group operations - Disadvantage: latency and possibly performance.
Is send/receive acknowledged or transacted?
The send/receive operations on a Session are either acknowledgedor transacted.
Does auto acknowledgement affect a session?
On the other hand in a JMS Session with auto-acknowledgement, received messages, after they are delivered to application, are automatically removed from the JMS Provider without the need for application to call commit/rollback. Auto-acknowledge has no effect on a transacted session.
What is a persistent JMS?
The messages' fate depends not upon the transaction options outlined earlier, but rather upon the delivery mode. There are two delivery modes: nonpersistent and persistent. Messages with nonpersistent delivery modes are potentially lost if the JMS provider fails. Messages with persistent delivery modes are logged and stored to a stable storage. The JMS provider saves these messages to a stable storage, such as a database or a file system, and eventually delivers them to the application for processing.
What are the acknowledgement modes in JMS?
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.
How to implement auto acknowledgement mode?
To implement the auto acknowledgement mode, when you create the receiver's session, specify false as the first argument and Session.AUTO_ACKNOWLEDGE as the second argument of the createSession () factory method. Specifying false creates a nontransacted session. The second parameter creates a session that automatically acknowledges messages. A message is automatically acknowledged when it successfully returns from the receive () method. If the receiver uses the MessageListener interface, the message is automatically acknowledged when it successfully returns from the onMessage () method. If a failure occurs while executing the receive () method or the onMessage () method, the message is automatically redelivered. The JMS provider carefully manages message redelivery and guarantees once-only delivery semantics.
What is JMS in architecture?
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.
What is client mode?
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.
What is auto mode in JMS?
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.
How does an application participate in a transaction?
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.
What method does a JMS client use to start a transaction?
The JMS client must use the UserTransaction 's begin method to start a transaction. Unlike transacted sessions, the UserTransaction API is not a chained model, and clients must explicitly begin a transaction.
When to use transacted session?
Transacted sessions are used when transactional behavior is required within a single JMS session. Other resources such as database or EJB operations cannot participate in a transacted session's transaction. Passing a boolean true argument when the session is created creates a transacted session. The acknowledgment mode is also specified, but it is ignored for transacted sessions.
What is JMS acknowledgment mode?
The JMS acknowledgment modes provide varying levels of reliability for message consumers, but enterprise applications often require stronger, transactional guarantees. For instance, an application might need to dequeue a message, update some database tables, and enqueue the message on another JMS queue. If any of these operations fails or a system failure occurs, the entire operation should roll back to its original state. JMS offers two transactional options: transacted sessions and an integration with the WebLogic Server's Java Transaction API (JTA) transaction service.
Why should JTA be preferred to transacted sessions?
JTA UserTransactions should be preferred to transacted sessions since the transaction can enlist other resources such as JDBC or EJB access.
What happens when a transaction commits?
When the transaction commits, any JMS messages produced within the transaction are enabled for delivery. Any received messages will be acknowledged with a commit. A transaction abort will release any sent messages while received messages will be returned to their JMS destination and redelivered.
Can JTA be used with non-transaction sessions?
The JTA UserTransaction API may only be used with nontransacted sessions. A transacted session will not participate in any JTA transaction, and it will ignore any UserTransaction commits or rollbacks.
Can a sender perform JDBC operations?
The sender might then perform some JDBC operations.
Acknowledgement mode
Auto mode: In auto mode, the messages sent or received from the session are acknowledged automatically. This is one of the simplest modes, and it expresses JMS Transaction power by enabling a once-only message delivery guarantee.
Transaction options
Transacted session: An application can participate in a transaction by creating a transacted session (or local transaction) in which the application completely controls the message delivery by either committing or rolling back the session.
Auto acknowledgement
To implement the auto acknowledgement mode, while creating JMS transaction the receiver’s session, specify false as the first argument and Session.AUTO_ACKNOWLEDGE as the second argument in the createSession () factory method. Specifying false will create a non-transacted session.
Duplicates okay acknowledgement
This mode closely resembles the auto acknowledgement mode. However, rather than passing Session.AUTO_ACKNOWLEDGE, you can specify Session.DUPS_OK_ACKNOWLEDGE as the acknowledgement mode of createSession () second argument. During failure recovery, certain messages are probably delivered more than once.
Client acknowledgement
In this mode, when you create the receiver’s session, you need to specify false as createSession () first argument and Session.CLIENT_ACKNOWLEDGE as the second argument. Specifying false will create a non-transacted session. In this mode, invoking the Message class acknowledge () method will explicitly acknowledges the message.
Transacted session
For implementing the transacted session mode, when creating the receiver’s session, you need to specify true as createSession () first argument and ignore the createSession () method second argument.
Message-driven bean with CMTD
Upon deploying a message-driven bean, CMTD is specified in the XML deployment descriptor. The following XML fragment from the ejb-jar.xml depicts that the <transaction-type> attribute is Container:
