简体   繁体   English

Rabbitmq consumer_timeout 行为未按预期工作?

[英]Rabbitmq consumer_timeout behavior not working as expected?

I have hard times to demonstrate that the consumer_timeout setting is working as expected.我很难证明consumer_timeout设置按预期工作。 I may have done things wrong or misunderstood the consumer_timeout behavior.我可能做错了事情或误解了 consumer_timeout 行为。

All my code for testing is available here: https://github.com/Rafarel/rabbitmq-tests我所有的测试代码都可以在这里找到: 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.基本上,我将consumer_timeout设置为 10000 毫秒(10 秒),然后在尝试确认消息之前尝试使用比超时值(20 秒)休眠时间稍长的回调来使用消息。

I am supposed to have a PRECONDITION_FAILED exception due to the timeout, but it is not the case.由于超时,我应该有一个 PRECONDITION_FAILED 异常,但事实并非如此。 I have the exception if I set the SLEEP_DURATION in receive_timeout.py way more than the consumer_timeout value like 60 seconds.如果我在receive_timeout.py中将SLEEP_DURATION设置为超过consumer_timeout值(如 60 秒),我会遇到异常。

Quote fromhttps://www.rabbitmq.com/consumers.html#acknowledgement-timeout引自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.如果消费者在超过超时值(默认为 30 分钟)的时间内未确认其交付,则其通道将关闭并出现 PRECONDITION_FAILED 通道异常。

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:您可以在RabbitMQ服务器上运行以下命令动态设置consumer_timeout值:

rabbitmqctl eval 'application:set_env(rabbit, consumer_timeout, 36000000).'

This will set the new timeout to 10 hrs (36000000ms).这会将新超时设置为 10 小时(36000000 毫秒)。 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有 Docker 张图片

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" . 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 consumer_timeout 从来都不是为了提供任何精度,它主要是为了保护仲裁队列和非常长时间运行的消费者

timeouts will only be evaluated every 60 seconds by default.默认情况下,超时只会每 60 秒评估一次。 This interval is controlled by the channel_tick_interval setting (edited)此间隔由 channel_tick_interval 设置控制(已编辑)

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您的代码也阻止了 IO: https://github.com/Rafarel/rabbitmq-tests/issues/1

Also

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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