在不禁用心跳的情况下保持 pika BlockingConnection 存活 [英] Keep pika BlockingConnection alive without disabling heartbeat

查看:90
本文介绍了在不禁用心跳的情况下保持 pika BlockingConnection 存活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个带有 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.

参考:

Socket Error: 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).

这篇关于在不禁用心跳的情况下保持 pika BlockingConnection 存活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆