RabbitMQ: How to prevent QueueDeclare to automatically generate a new Queue
Passive declarations are made for this. Use IModel.QueueDeclarePassive()
:
model.QueueDeclarePassive("queue-name");
This does nothing if the queue already exists, and raises an exception otherwise.
You can bind to existing queue without declaring a new one.
try
{
channel.QueueBind(queueName, exchange, routingKey);
}
catch (RabbitMQ.Client.Exceptions.OperationInterruptedException ex)
{
// Queue not found
}
An example of the exception thrown if the queue you're trying to bind does not exist:
RabbitMQ.Client.Exceptions.OperationInterruptedException: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=404, text="NOT_FOUND - no queue 'TestQueue' in vhost '/'", classId=50, methodId=20, cause=