Message acknowledgement v42.7.3.1
Acknowledgement of messages is controlled by the two arguments to the createSession()
and createQueueSession()
methods:
If the first argument is true, it indicates that the session mode is transacted, and the second argument is ignored. However, if the first argument is false, then the second argument comes into play, and the client can specify different acknowledgment modes.
These acknowledgment modes include,
- Session.AUTO_ACKNOWLEDGE
- Session.CLIENT_ACKNOWLEDGE
- Session.DUPS_OK_ACKNOWLEDGE
Transacted session
In transacted sessions, messages are both sent and received during a transaction. These messages are acknowledged by making an explicit call to commit()
. If rollback()
is called, all received messages will be marked as not acknowledged.
A transacted session always has an active transaction. When a client calls the commit()
or rollback()
method, the current transaction is either committed or rolled back, and a new transaction is started.
This example explains how the transacted session works:
AUTO_ACKNOWLEDGE mode
If the first argument to createSession()
or createQueueSession()
is false and the second argument is Session.AUTO_ACKNOWLEDGE
, the messages are automatically acknowledged.
DUPS_OK_ACKNOWLEDGE mode
This mode instructs the session to lazily acknowledge the message, and it is okay if some messages are redelivered. However, in EDB JMS, this option is implemented the same way as Session.AUTO_ACKNOWLEDGE
, where messages will be acknowledged automatically.
CLIENT_ACKNOWLEDGE mode
If the first argument to createSession()
or createQueueSession()
is false and the second argument is Session.CLIENT_ACKNOWLEDGE
, the messages are acknowledged when the client acknowledges the message by calling the acknowledge()
method on a message. Acknowledging happens at the session level, and acknowledging one message will cause all the received messages to be acknowledged.
For example, if we send 5 messages and then receive the 5 messages, acknowledging the 5th message will cause all 5 messages to be acknowledged.