Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMS Sessions, "transacted" and "auto-acknowledge"

Tags:

jms

jms-topic

What does JMS session exactly mean?

What does it mean that a JMS session can be or not "transacted"?

What does it mean that a JMS session can be or not with "auto-acknowledge"?

like image 829
Johan Avatar asked Jan 28 '18 14:01

Johan


People also ask

What is transacted session in JMS?

A transacted session supports a single series of transactions. Each transaction groups a set of produced messages and a set of consumed messages into an atomic unit of work. In effect, transactions organize a session's input message stream and output message stream into series of atomic units.

Can a JMS session be transactional?

JMS applications can run local transactions by first creating a transacted session. An application can commit or roll back a transaction.

What is JMS Acknowledgement?

Acknowledgement is the way that a consumer informs the JMS provider that it has successfully received a message. On the producer side, the only notion of acknowledgement consists of a successful invocation of either the topic publishe's publish method or the queue sender's send method.

What is Session Auto_acknowledge?

Session. AUTO_ACKNOWLEDGE: The session automatically acknowledges a client's receipt of a message either when the client has successfully returned from a call to receive or when the MessageListener it has called to process the message returns successfully.


2 Answers

All the information is there in JMS Specification here A JMS Session is an object that maintains connection to a JMS Provider for sending and receiving messages.

A transacted session supports a single series of transactions. Each transaction groups a set of produced messages and a set of consumed messages into an atomic unit of work. In effect, transactions organize a session’s input message stream and output message stream into series of atomic units. When a transaction commits, its atomic unit of input is acknowledged and its associated atomic unit of output is sent. If a transaction rollback is done, its produced messages are destroyed and its consumed messages are automatically recovered.

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.

like image 181
Shashi Avatar answered Sep 20 '22 15:09

Shashi


You could view a JMS Session as the link between a connection and a thread's work on that connection. 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.

Imagine a consumer crash: usually you want to redeliver a message if the consumer said it hasn't processed a message yet. So an acknowledgment (ACK) can be send from consumer to Broker to tell the JMS Broker that the message has been processed. Not just received but also stored in the Database, or whatever work the consumer is doing. If the consumer is restarted after the crash it will receive all messages that have not yet been acknowledged.

There are different forms of ACKs: auto-acknowledge means that the API will call acknowledge() for you after you've returned from your callback. In the other cases, you will have to call acknowledge() yourself.

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

One main purpose of the Session is to keep a transaction's state. If your session was created to be transacted (SESSION_TRANSACTED) it knows all the messages that you are planning to send within your transaction and if that transaction is committed or rolled-back.

like image 31
Axel Podehl Avatar answered Sep 23 '22 15:09

Axel Podehl