我不熟悉Qpid Proton Python和AMQP。有一件事我有点被卡住了,我希望我能得到社区的一些支持
我的应用程序要求之一是,如果从我的应用程序到message broker(ActiveMQ)的连接丢失,则每分钟重新尝试一次连接
从源代码和这个:documentation(第5.2.4节,第14页)来看,似乎我可以在on_启动事件期间调用“container.connect()”方法时,为“reconnect”参数创建一个自定义退避实例
因此,我对自定义退避实例执行了类似的操作:
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_启动期间:
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())
问题:
任何建议都将不胜感激,谢谢
目前没有回答
相关问题 更多 >
编程相关推荐