0
votes

I have a situation in which the I'm reading messages from a queue using a message consumer (javax.jms.MessageConsumer) . The session used is using AUTO_ACKNOWLEDGE mode.

From what I've read so far on AUTO_ACK mode:

In auto acknowledgement if the consumer's onMessage() method completes without error the message is considered received and processed successfully, it'll be then removed from the JMS server.

My question is when is the message considered to be ACK by the JMS producer considering I`m not using an MDB that has an onMessage() method but reading the messages by using the message consumer described earlier.

Is the message ACK'ed once I successfully read it using the messageConsumer ? What will happen if further down the logic-chain a method that uses the respective message will throw an error ? Will the message already be ACK'ed by that time ?

1

1 Answers

1
votes

The Javadoc for the AUTO_ACKNOWLEDGE constant says this:

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.

I suspect you are calling receive on the MessageConsumer (although you don't explicitly state that) so if you set AUTO_ACKNOWLEDGE it is acknowledged by the time receive returns.

Of course if you have a transacted session then the acknowledge mode is ignored and the message isn't considered received until the session is committed.