I have tried to google this, but have not been successful. If I am using AUTO_ACKNOWLEDGE
, and I have a consumer client written in Java, when is the message acknowledged? I am using a MessageListener
which contains an onMessage
method. Is the acknowledgement sent back to the server before onMessage
or after onMessage
completes or at some other point? Thanks in advance for any help anyone is able to provide!
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.
DUPS_OK_ACKNOWLEDGE. The session acknowledges the messages received by the application at times it selects. Using this acknowledgment mode reduces the amount of work the session must do, but a failure that prevents message acknowledgment might result in more than one message becoming available for delivery again.
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.
Please check this one (Wayback Machine link used as article went offline since 2020)
With AUTO_ACKNOWLEDGE
mode the acknowledgment is always the last thing to happen implicitly after the onMessage()
handler returns. The client receiving the messages can get finer-grained control over the delivery of guaranteed messages by specifying the CLIENT_ACKNOWLEDGE
mode on the consuming session.
The use of CLIENT_ACKNOWLEDGE
allows the application to control when the acknowledgment is sent. For example, an application can acknowledge a message - thereby relieving the JMS provider of its duty - and perform further processing of the data represented by the message. The key to this is the acknowledge() method on the Message object, as shown in Listing 1.
The acknowledge()
method informs the JMS provider that the message has been successfully received by the consumer. This method throws an exception to the client if a provider failure occurs during the acknowledgment process. The provider failure results in the message being retained by the JMS server for redelivery.
CLIENT_ACKNOWLEDGE
With this acknowledgment mode, the client acknowledges a consumed message by calling the message's acknowledge method.
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); ... msg = (TextMessage) consumer.receive(); //acknowledge msg.acknowledge();
AUTO_ACKNOWLEDGE
With this acknowledgment mode, the session automatically acknowledges a client's receipt of a message either when the session has successfully returned from a call to receive or when the message listener the session has called to process the message successfully returns.
Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
source
Best example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With