Search code examples
c#rabbitmqconsuming

RabbitMQ consuming one message before receiving a new


If I sends the message to a task inside my service and returns from the RabbitMQ “Received” callback I get a new callback immediately. This is not intended since my service then will work as a new queue and makes spawning of a new worker more less useless since the first service has dequeued all messages.

I can see in the python examples, that the callback acks the message when it’s done but the C# doesn’t. Can this ack bed used for blocking for new messages until the current message is processed.

Also finds blocking the “Received” event function with a semaphore until processing is done very very hacky.


Solution

  • You need to set consumer prefetch to 1: https://www.rabbitmq.com/consumer-prefetch.html

    Ack the message when you're done with it, and you'll get the next one.