5

I am using EasyNetQ and I am wondering how to fetch an existing IExchange and IQueue without subscribing beforehand?

In the IAdvanceBus I can only see:

  • ExchangeDeclareAsync
  • QueueDeclareAsync

But I am not sure really whether those will override an existing queue or exchange with the same name?

Also how can I be sure that that queue or exchange exist before trying to fetch / declare it?

Natalie Perret
  • 8,013
  • 12
  • 66
  • 129

2 Answers2

2

The functions ExchangeDeclareAsync and QueueDeclareAsync will not override existing exchanges / queues. If an exchange or queue with the given name already exists, it will simply be returned. In fact, exchanges and queues in RabbitMQ are immutable, ie. you cannot change their properties after creating them.

This also means that if you call Exchange/QueueDeclareAsync with different properties than the existing exchange or queue, you will get a RabbitMQ.Client.Exceptions.OperationInterruptedException about PRECONDITION_FAILED notifying you exactly about what went wrong.

w5l
  • 5,341
  • 1
  • 25
  • 43
1

If you have the management plugin activated in RabbitMQ you can use EasyNetQ's client for the management API. Documentation.

For example:

var queues = managementClient.GetQueues();

foreach (Queue queue in queues)
{
    Console.Out.WriteLine("queue.Name = {0}", queue.Name);
}

However you won't override a queue or exchange if you redeclare it. Nothing happens.

John
  • 192
  • 3
  • 12