简体   繁体   中英

Rabbitmq consumer_timeout behavior not working as expected?

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 fromhttps://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!

Some useful tips:

  1. Dynamic configuration

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).'

  1. With Docker images

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" .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM