5
votes

I'm using the amqplib library for nodejs to work with RabbitMQ. I'm trying to check whether a queue exists by using the function checkQueue:

mychannel.checkQueue('xxx', function (err, ok) { 
    console.log(err);
    console.log(ok)
});

But it not only throws an error, but also closes the channel. How can I safely check if the queue exists?

1

1 Answers

0
votes

You can't without risking to destroy the channel. The workaround is to create a temporary channel which you can use to do the check.

A comment from amqp.node dev: (https://github.com/squaremo/amqp.node/issues/280)

The behaviour of checkQueue is dictated by the protocol, but it can be worked around. One tactic is to create a "sacrificial" extra channel with which to test whether the queue exists. Once you have the answer, you can throw the extra channel away, or keep it around for more tests.