[rabbitmq-discuss] Turning consumers on/off in Erlang client
matthew at rabbitmq.com
Mon Aug 30 18:43:18 BST 2010
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.
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
3. use amqp_channel:register_default_consumer to set a consumer which
will be invoked if the ctag isn't recognised.
More information about the rabbitmq-discuss