Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RabbitMQ only listens to the first message on a queue

Tags:

c#

rabbitmq

I'm having an issue with my Rabbit queues that is currently only reacting to the first message in queue, after that any other messages being pushed are being ignored.

I start with instantiating the connection and declaring the queue in my IQueueConnectionProvider:

var connectionFactory = new ConnectionFactory() { HostName = hostName };
var connection = _connectionFactory.CreateConnection();
var channel = connection.CreateModel();

That IQueueConnectionProvider is then used in my IQueueListener as a dependency with just one method:

public void ListenToQueue(string queue)
{
    var channel = _queueConnectionProvider.GetQueue();

    var consumer = new EventingBasicConsumer(channel);
    consumer.Received += (model, ea) =>
    {
        string path = @"d:\debug.log.txt";
        File.AppendAllLines(path, new List<string>() {"MESSAGE RECEIVED", Environment.NewLine });

        var body = ea.Body;
        var message = Encoding.UTF8.GetString(body);

        channel.BasicAck(ea.DeliveryTag, false);
    };

    channel.BasicConsume(queue, true, consumer);

}

My log file ends up being just one line "MESSAGE RECEIVED", however I can see in the Rabbit ui interface that my other services are pushing the messages to that queue just fine.

Is there something I'm missing here?

like image 284
LanFeusT Avatar asked Jan 05 '16 02:01

LanFeusT


1 Answers

This was a dumb mistake... yet again.

channel.BasicConsume(queue, false, consumer);

This was what I needed. I want to manually acknowledge my messages, therefore noAck needs to be false;

like image 125
LanFeusT Avatar answered Sep 25 '22 19:09

LanFeusT