Qpid 质子 Python 重新连接每分钟尝试一次

问题描述

我是 Qpid Proton Python 和 AMQP 的新手。有一件事我有点坚持,我希望我能得到社区的一些支持

我的应用程序要求之一是每分钟重新尝试连接,如果从我的应用程序到消息代理 (ActiveMQ) 的连接丢失。

从源代码和这个:documentation(第 5.2.4 节,第 14 页),似乎我可以在调用“container.connect()”时为“reconnect”参数创建一个自定义 Backoff 实例" on_start 事件期间的方法

所以我为我的自定义 Backoff 实例做了这样的事情:

class Backoff:
    """
    A modified reconnect strategy that retries,every 60s. 
    Repeated calls to :meth:`next` returns a value for the next delay
    """

    def __init__(self):
        self.delay = 60

    def reset(self):
        """
        Reset the backoff delay to 60 seconds.
        (This method is required for Qpid Proton Library)
        """
        self.delay = 60

    def next(self):
        """
        Modified the backoff mechanism to attempt reconnect every 60s

        :return: The next delay in seconds.
        :rtype: ``float``
        """
        return self.delay

在 on_start 期间:

def on_start(self,event):
    self.container = event.container
    self.conn = self.container.connect(
        url=self.url,user=self.user,password=self.password,reconnect=Backoff())

问题:

  1. 我可以知道如何测试这是否真的正常工作?我在自定义 Backoff 实例的“next()”方法中放置了打印语句并断开了 Wifi 以模拟断开连接,但是,重新连接尝试似乎不起作用。
  2. 在容器运行时,我如何捕获断开连接事件并尝试重新连接?

任何建议将不胜感激,谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)