Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

rabbitmq

amqp

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.

like image 769
zum_grauen_hase Avatar asked Dec 07 '25 22:12

zum_grauen_hase


1 Answers

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.

like image 110
cantSleepNow Avatar answered Dec 11 '25 13:12

cantSleepNow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!