Dnyandeo Narkhede
Dnyandeo Narkhede

Reputation: 41

How do we fetch real time messages from RabbitMQ queue without having any delay in .NET?

I have written code to fetch messages from RabbitMQ queue and executing that program every 5 minutes by adding in task scheduler.

But, this is not realtime processing. It has delay of 5 min.

I want to make it process in realtime. As on someone add message in RabbitMQ Queue .NET program should immediately pick it for further processing.

Any pointer would be appreciated.

Upvotes: 2

Views: 866

Answers (1)

Archlight
Archlight

Reputation: 2079

I guess you are not talking about true realtime but getting the message as quickly as possible.

This is done by using EventingBasicConsumer in RabbitMQ

var consumer = new EventingBasicConsumer(model);
consumer.Received += (ch, ea) =>
    {
       try
       {
            var body = ea.Body;
            var message = Encoding.UTF8.GetString(body);

        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw;
        }
    };
channel.BasicConsume(queueName, false, consumer);

Upvotes: 1

Related Questions