Oracle GlassFish Message Queue 4.4.2 Developer's Guide for Java Clients

Acknowledging Messages

If you have specified client-acknowledge as your session’s acknowledgment mode (see Acknowledgment Modes), it is your client application’s responsibility to explicitly acknowledge each message it receives. If you have received the message synchronously, using a message consumer’s receive (or receiveNoWait) method, you should process the message first and then acknowledge it; if you have received it asynchronously, your message listener’s onMessage method should acknowledge the message after processing it. This ensures that the message broker will not delete the message from persistent storage until processing is complete.

Note –

In a transacted session (see Transacted Sessions), there is no need to acknowledge a message explicitly: the session’s acknowledgment mode is ignored and all acknowledgment processing is handled for you automatically by the Message Queue client runtime. In this case, the session’s getAcknowledgeMode method will return the special constant Session.SESSION_TRANSACTED.

Table 2–16 shows the methods available for acknowledging a message. The most general is acknowledge, defined in the standard JMS interface javax.jms.Message:


This acknowledges all unacknowledged messages consumed by the session up to the time of call. You can use this method to acknowledge each message individually as you receive it, or you can group several messages together and acknowledge them all at once by calling acknowledge on the last one in the group.

Table 2–16 Message Acknowledgment Methods




Acknowledge all unacknowledged messages for session 


Acknowledge this message only 


Acknowledge all unacknowledged messages through this one 

The Message Queue version of the Message interface, defined in the package com.sun.messaging.jms, adds two more methods that provide more flexible control over which messages you acknowledge. The acknowledgeThisMessage method just acknowledges the single message for which it is called, rather than all messages consumed by the session; acknowledgeUpThroughThisMessage acknowledges the message for which it is called and all previous messages; messages received after that message remain unacknowledged.