You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Gordon Sim <gs...@redhat.com> on 2012/01/18 11:44:40 UTC

Re: when a message is considered delivered? How deliver and deliver only once is guaranteed?

On 01/17/2012 10:28 PM, Gang, Litao wrote:
> when a message in a queue is marked as consumed?   Ideally it should be right before the received(.) callback is invoked.  But from what I see looks like it is not.

Assuming auto-ack is in use (and is set to 1), the messages will be 
acknowledged immediately *after* the received callback. The reason for 
this is that should the client process crash just as the received() call 
is being made, it may not get time to process the message.

> As a workaround, can I call some routine to tell the broker to remove the message on queue?

Yes, you can turn off auto-ack and do the accept yourself. That way you 
can do it before processing the message if desired, or as part of any 
poisoned letter check.

The simplest way to do this is probably to use accept() method on the 
associated Subscription object. This will be synchronous as well, 
meaning that the call won't return until the broker has received the 
accept. The auto-ack property on the SubscriptionSettings can be set to 
0 to turn off automatic accepts.

(Another pattern I'll mention just for completeness, is to use 
LocalQueue rather than MessageListener. Here you explicitly pop off the 
next message in order to process it and the accept is issued at that 
point, i.e. generally before any processing. This is similar I believe 
to JMS where messages are accepted on returned from the listener 
callback if in use, or on returning from a receive() call if not.)

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org