我正在使用 pika 0.10.0 和 python 2.7 版本开发 RabbitMQ 消费者.在我的消费者客户端中,我有一个进程根据输入消息运行一段时间.它可以从 3 到 40 分钟不等.我不想禁用心跳.相反,我正在寻找一些可以使连接保持活动状态的回退机制,直到将 delivery_tag 发回.这可能吗?
I am developing an RabbitMQ consumer with pika 0.10.0, and python 2.7 version.In my consumer client, I have a process that runs for a time period depending on input message. It can vary from 3 to 40 minutes. I do not want to disable heartbeat. Instead I am looking for some collback mechanism that can keep the connection alive until the delivery_tag is sent back. Is that possible?
我得到的链接很少,所有人都建议禁用心跳作为解决方法.但我不想禁用它.
Few link I got, all are suggesting to disable the heartbeat as workaround. But I do not want to disable it.
参考:
套接字错误:104 消耗消息且任务耗时 #753
BlockingConnection 意外关闭 #734
另外,如果需要任何额外信息,请告诉我.提前致谢.
Also, please let me know if any extra information is required. Thanks in advance.
推荐答案唯一的解决方案是定期发送心跳帧.
The only solution is to send heartbeat frames periodically.
使用 BlockingConnection 时,您必须调用 process_data_events 函数足够频繁(time_limit 为零是可以的).使用 SelectConnection 或其他异步适配器时,您必须确保没有任何进程阻塞,以便可以发送帧.
When using a BlockingConnection, you have to call the process_data_events function frequently enough (a time_limit of zero is ok). When using a SelectConnection or other async adapters, you have to ensure none of your processes are blocking, so that frames can be sent.
如果您的任务长时间运行并且由于某种原因无法轻松中断或拆分进程,则可以在另一个线程/进程中运行该任务,并且仍然让 pika 从主线程发送帧.请记住,您应该避免跨线程使用 pika 连接(pika 目前不是线程安全的).
If your task is long running and you can't interrupt or split the process easily for some reason, you can run the task in another thread/process, and still have pika sending frames from the main thread. Just keep in mind that you should avoid using pika connections across threads (pika is not thread-safe at the moment).
更多推荐
在不禁用心跳的情况下保持鼠兔 BlockingConnection 处于活动状态
发布评论