[rabbitmq-discuss] Why does Channel.queueDeclarePassive close the channel?

Simon MacMullen simon at rabbitmq.com
Tue Feb 22 10:32:14 GMT 2011

On 18/02/11 17:03, Yuesong Wang wrote:
> Now on the producer side, a dumb but easy way to make sure the queue
> gets recreated if missing is to always declare the queue and binding
> before every publish.  It works but I'd imagine it is very inefficient,
> yeah?

If you do so before every basic.publish invocation, yes! Declaring a 
queue or binding that already exists is pretty cheap on the server, but 
you still end up making a synchronous call over the network.

> The consumer code is a bit more complicated with the use of
> QueueConsumer and Channel.basicConsumer. For a running consumer to use a
> recreated queue, do I have to instantiate a new QueueConsumer, and call
> Channel.basicConsumer again? I'm new to RabbitMQ and there seems to be a
> lot of options to go about this. Any pointers are much appreciated.

The usual pattern would be to declare the objects you want to use after 
starting a channel. But if you're concerned about a queue going away 
then I suspect the best thing to do is catch the connection / channel 
closing, and then if that happens tear down, reconnect and redeclare.

Cheers, Simon

Simon MacMullen
Staff Engineer, RabbitMQ
SpringSource, a division of VMware

More information about the rabbitmq-discuss mailing list