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!
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);
© 2022 - 2024 — McMap. All rights reserved.
onMessage()
? Will the message be redelivered if theAUTO_ACKNOWLEDGE
is set? – Eaten