[rabbitmq-discuss] Turning consumers on/off in Erlang client

Jon Brisbin jon at jbrisbin.com
Mon Aug 30 19:08:52 BST 2010

On Aug 30, 2010, at 12:43 PM, Matthew Sackman wrote:

> Hi Jon,
> On Mon, Aug 30, 2010 at 08:28:33AM -0500, Jon Brisbin wrote:
>> In my webhooks plugin, I'm trying to add some basic support for scheduling requests to go out at a particular time. Rather than try to implement some kind of sleep() call that waits until the next configured send window (which is getting a little complicated to manage) I'd like to simply cancel the consumer whenever the time is after a send window and start it back up whenever the window opens. I can figure out whether I'm in a send window easy enough but when I try to turn the consumer on and off (by asynchronously doing basic.cancel and basic.consume) it will give me an error something along the lines of (my logs have rolled past this error long ago, sorry for not having it verbatim) "unexpected delivery and no default consumer". I think this is coming from the erlang client, not the broker. 
> Hmm, that error was meant to catch the case where you do a basic.cancel,
> but you have outstanding unack'd messages and then you do
> basic.redeliver - the messages get resend but the client has since lost
> knowledge about that ctag, hence the error.

I probably do have unack'd messages waiting because I'm trying to limit the number of messages coming through. But I wasn't doing a redeliver, though...

> If you're doing a basic.cancel with nowait = true then I can certainly
> believe this would happen then too. But why are you doing that?
>> Is there a way to "nicely" manage the consumer so that it stops reasonably (not by simply interrupting whatever it's currently doing)? A kind of "cancel this consumer after the next message delivery"? Or should I be doing this in a different way?
> Yes - any of:
> 1. don't use the nowait version of basic.cancel
> 2. set qos prefetch_count to 1 and never cancel unless you have an
> unacknowledged message
> 3. use amqp_channel:register_default_consumer to set a consumer which
> will be invoked if the ctag isn't recognised.
> Matthew

Hmmm. I was using the defaults:

amqp_channel.call(Channel, #'basic.cancel'{ consumer_tag=Tag }),

I probably want to do #3 as well, no matter what. I don't really *care* if a message sneaks through after a window is closed. I don't have to be that accurate. I just need it to stop any new messages from being processed until I start the consumer again when another send window has opened. 


J. Brisbin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20100830/176844df/attachment.htm>

More information about the rabbitmq-discuss mailing list