nats-python
nats-python copied to clipboard
Auto reconnect
Hi, thank you for the nats-python. It would be great if there will be an option to set auto reconnect to server. I have found solution to detect disconnects when publish: `
def publish(self, subject, data):
try:
self._nats.publish(subject, payload=bytes(json.dumps(data), encoding='utf-8'))
except BrokenPipeError:
while True:
try:
self._nats.reconnect()
self.publish(subject, data)
break
except:
pass
`
But I don't know how to detect disconnects when subscribe, program just freezes
Hi and thanks, glad that nats-python solves your problems!
About reconnects. Yes, this is a known problem (you can find a similar issue and a proposal to solve it at #5) and honestly, I don't know how to solve it in the right way. We need somehow understand is socket healthy or not. I don't have free time for now to deep dive into, but if you want to spend some time and find a solution it would be great. PR is always welcome.