Reputation: 356
I have hard times to demonstrate that the consumer_timeout
setting is working as expected.
I may have done things wrong or misunderstood the consumer_timeout behavior.
All my code for testing is available here : https://github.com/Rafarel/rabbitmq-tests
Basically, I have a consumer_timeout
set to 10000ms (10sec) and then I try to consume the message with a call back
that sleeps a bit longer than the timeout value (20sec) before trying to acknowledge the message.
I am supposed to have a PRECONDITION_FAILED exception due to the timeout, but it is not the case.
I have the exception if I set the SLEEP_DURATION
in receive_timeout.py
way more than the consumer_timeout
value like 60 seconds.
Quote from https://www.rabbitmq.com/consumers.html#acknowledgement-timeout
If a consumer does not ack its delivery for more than the timeout value (30 minutes by default), its channel will be closed with a PRECONDITION_FAILED channel exception.
If someone could help me understand what I'm doing wrong that would be great, thanks!
Upvotes: 12
Views: 20063
Reputation: 2713
Some useful tips:
You can dynamically set the consumer_timeout
value by running the following command on the RabbitMQ server:
rabbitmqctl eval 'application:set_env(rabbit, consumer_timeout, 36000000).'
This will set the new timeout to 10 hrs (36000000ms). For this to take effect, you need to restart your workers though. Existing worker connections will continue to use the old timeout.
You can check the current configured timeout value as well:
rabbitmqctl eval 'application:get_env(rabbit, consumer_timeout).'
If you are running RabbitMQ via Docker image, here's how to set the value: Simply add -e RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS="-rabbit consumer_timeout 36000000"
to your docker run
OR set the environment RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS
to "-rabbit consumer_timeout 36000000"
.
Upvotes: 29
Reputation: 22712
For future readers:
The consumer_timeout was never meant to provide any kind of precision, it is there to protect quorum queues mostly and very long running consumers
timeouts will only be evaluated every 60 seconds by default. This interval is controlled by the channel_tick_interval setting (edited)
so try lowering the tick interval to get a bit more precision.
Also your code is blocking the IO: https://github.com/Rafarel/rabbitmq-tests/issues/1
Also
Upvotes: 11