5

I am looking at using EasyNetQ for interacting with RabbitMQ and wondering if it can support following case:

  1. Queue is declared externally with some arbitrary arguments (e.g. x-message-ttl)
  2. Client code using EasyNetQ sends and receives messages from that queue.

Possibilities I have found are:

  • Simple IBus API requires that queue has default parameters
  • Advanced IAdvancedBus API allows to specify arguments of the declared-queue but not all (e.g. x-max-length can't be set)

The question is can I just use existing queue with custom parameters and without need to specify them?

Donut
  • 110,061
  • 20
  • 134
  • 146
Oleksii Zuiev
  • 566
  • 1
  • 7
  • 17

2 Answers2

8

If the queue already exists and you know its name, couldn't you use the IAdvancedBus.Consume<T> method (and not worry about IAdvancedBus.QueueDeclare)?

For example:

var queueName = "TheNameOfYourExistingQueue";
var existingQueue = new EasyNetQ.Topology.Queue(queueName, false);

// bus should be an instance of IAdvancedBus
bus.Consume<TypeOfYourMessage>(existingQueue, 
   (msg, info) => 
      {
         // Implement your handling logic here
      });

Note that EasyNetQ might have trouble automatically deserializing messages into instances of TypeOfYourMessage. If that is the case, one way to solve it would be to bypass EasyNetQ's message serializer so that you can access the byte array of the message directly. Use the following overload to Consume if you wish to go that route:

void Consume(IQueue queue, Func<Byte[], MessageProperties, MessageReceivedInfo, Task> onMessage);
Donut
  • 110,061
  • 20
  • 134
  • 146
1

Even with solution 10477404, parameters like isDurable, isExclusive, isAutoDelete, and arguments must match the original Queue declaration to avoid creating a new one.

For safety, and if you have a way to know the original queue declaration parameters, use them to create the queue with IAdvancedBus.QueueDeclare() or IAdvancedBus.QueueDeclareAsync()