在不禁用心跳的情况下保持鼠兔 BlockingConnection 处于活动状态

编程入门 行业动态 更新时间:2024-10-18 03:33:12
本文介绍了在不禁用心跳的情况下保持鼠兔 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.

参考:

套接字错误: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 处于活动状态

本文发布于:2023-11-24 04:42:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624010.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:情况下   状态   BlockingConnection

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!