I'm new to Qpid Proton Python and AMQP. There is one thing that I'm a bit stuck on which I hope I can get some support from the community.
One of my application requirements is to re-attempt connection every minute if the connection from my application to the message broker (ActiveMQ) has been lost.
From the source code and this: documentation (Section 5.2.4, page 14), it seems like I can create a custom Backoff instance to the "reconnect" parameter when calling the "container.connect()" method during on_start event.
So I did something like this for my custom Backoff instance:
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
During 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())
Questions:
- May I know how can I test if this is actually working fine? I placed print statements in the "next()" method of my custom Backoff instance and disconnected my Wifi to simulate a disconnect, however, the reconnection attempt doesn't seem to work.
- As the container runs, how can I capture disconnection events and attempt reconnection?
Any advice will be greatly appreciated, thank you!