EasyNetQ - getting from an existing queue

I am considering using EasyNetQ to interact with RabbitMQ and wondering if it can support the following case:

  • The queue is declared externally with arbitrary arguments (e.g. x-message-ttl)
  • Client code using EasyNetQ sends and receives messages from this queue.

The possibilities I found:

  • The IBus simple API requires default parameters in the queue
  • Advanced IAdvancedBus API allows you to specify declared queue arguments, but not all (for example, it is not possible to set the maximum x-max length)

The question is, can I just use an existing custom queue and not specify them?

+3


source to share


1 answer


If the queue already exists and you know its name, can't you use the method IAdvancedBus.Consume<T>

(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
      });

      



Please note that EasyNetQ may have problems with automatic deserialization of messages in instances TypeOfYourMessage

. If so, one way to address this would be to bypass the EasyNetQ serial message interface so that you can access the message byte array directly. Use the following overload for Consume

if you want to go this route:

void Consume(IQueue queue, Func<Byte[], MessageProperties, MessageReceivedInfo, Task> onMessage);

      

+3


source







All Articles