微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。