RabbitMQ C# API Event based Message Consumption

Jigar Sheth picture Jigar Sheth · Aug 10, 2010 · Viewed 9.7k times · Source
while (true)
{
    BasicDeliverEventArgs e = (BasicDeliverEventArgs)Consumer.Queue.Dequeue();
    IBasicProperties properties = e.BasicProperties;
    byte[] body = e.Body;
    Console.WriteLine("Recieved Message : " + Encoding.UTF8.GetString(body));
    ch.BasicAck(e.DeliveryTag, false);
}

This is what we do when we Retrieve Message by subscription..We use While Loop because we want Consumer to listen Continously..what if i want to make this even based..that is when a new message arrives in the queue at that time only Consumer should Consume the message..or on any such similar event..

Answer

Carl Hörberg picture Carl Hörberg · Dec 14, 2010

use the RabbitMQ.Client.Events.EventingBasicConsumer for a eventing consumer instead of a blocking one.