Search code examples
rabbitmqamqp

RabbitMq: Disabling prefetching (prefetch_count=0) with auto-ack=false


Is it possible to disable prefetching with auto-ack=false? I just want to avoid reading message (prefetching) from a queue every time I acknowledge a message. I want to read a message only when I call a 'consume_message'. Setting prefetch_count=0 seems doesn't work and it's treated as 'no specif limit'.

UPDATED:
As I understand 'prefetch_count' is the number of messages cached on the client side (read locally into buffers). For example there is a use case:

(let's assume there is a queue we connect to and it has messages)

  1. Create a connection.
  2. Set Basic.Qos (prefetch_count=1)
  3. Start consuming Basic.Consume
  4. Due to the prefetch_count=1 one message is already transferred to the client and ready to be read and marked as not-ack'd.
  5. Reading message and then processing it.
  6. Then the message is ack'd. And everything starts from step 4.

I thought that setting prefetch_count to 0 would avoid the step 4 and a message is transferred only when you read it - no caching on the client side.


Solution

  • Prefetch and auto-acknowledgment are not related like that. Prefetch count is simply a number of unacknowledged messages prepared to be delivered to a specific consumer.

    Let's say you set prefetch count to N. If you set auto-ack to true, these means that these N messages are ACKed upon receiving. If you set it to false, this means that you still get the N messages but they're not ACKed until you manually ACK them.

    For the last part - try setting prefetch_count to 1.

    Also check this question and both answers.