简体   繁体   中英

JMS auto acknowledgment consumer processing happens in onMessage

I am not able to understand the below point on JMS AutoAck website: The below behaviour is followed in AUTO_ACKNOWLEDGE

Right after the onMessage method returns successfully after invoking the consumer's MessageListener (which might still in progress as per my understanding)

but as per my understanding, the Consumer implements MessageListener and does all the processing in the onMessage() method (which is implemented by Consumer)

One more question: I am not able to understand the diff between AUTO_ACKNOWLEDGE and DUPS_OK_ACKNOWLEDGE .
What I read is : DUPS_OK_ACKNOWLEDGE acknowledges lazily and might deliver the same message again, but not able to understand its practical implications.
Please help me with a practical example where AUTO_ACKNOWLEDGE is required and where DUPS_OK_ACKNOWLEDGE required


Added 5th Sep13 :Adding a point from Java Redeliver and transaction

Consider a failure occurring during message processing. What happens to the message? Will the message be lost or redelivered for successful processing later? The answers to these questions depend upon the transaction options you choose.

Some quotes from Transaction and redelivery in JMS


Auto mode : When a session uses auto mode, the messages sent or received from the session are automatically acknowledged. This is the simplest mode and expresses JMS's power by enabling once-only message delivery guarantee.

Reading a message means acknowledgement as well. So AUTO_ACKNOWLEDGE is simple. But if you are using a QueueReceiver without setMessageListener , and message processing fails, the message is lost.


Duplicates okay mode : When a session uses duplicates okay mode, the messages sent or received from the session are automatically acknowledged just like auto mode, albeit lazily. Under rare circumstances, the messages might be delivered more than once. This mode enables at-least-once message delivery guarantee.

Like AUTO_ACKNOWLEDGE , with less overhead, but the application must be able to deal with duplicate messages. You could use this, if performance matters, and duplicate messages are not a problem.


Client mode : When a session uses client mode, the messages sent or received from the session are not acknowledged automatically. The application must acknowledge the message receipt. This mode gives the application (rather than the JMS provider) complete control over message acknowledgement, at the cost of increased code complexity.

Use this approach, if you process one message, and after you have completed this task, then you explicitly call message.acknowledge() . If an exception happens during processing, the message is not lost (it will be redelivered).


As for the first part of your question, have a look at the Javadoc of AUTO_ACKNOWLEDGE . A quote:

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.

The linked article conforms to this description (acknowledge only, if onMessage is successful).

I have tested this using JBoss 7, using AUTO_ACKNOWLEDGE with a MessageListener : In case of an exception in onMessage , the message is actually not redelivered .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM