diff --git a/server/webhook-ingest/app/nats_client.py b/server/webhook-ingest/app/nats_client.py index 406c81a9..6d12ec3b 100644 --- a/server/webhook-ingest/app/nats_client.py +++ b/server/webhook-ingest/app/nats_client.py @@ -2,7 +2,6 @@ from app.config import settings from app.logger import logger - class NATSClient: def __init__(self, nats_url: str, nats_auth_token: str): self.nc = NATS() @@ -10,6 +9,18 @@ def __init__(self, nats_url: str, nats_auth_token: str): self.nats_auth_token = nats_auth_token async def connect(self): + async def disconnected_cb(): + logger.info('Got disconnected!') + + async def reconnected_cb(): + logger.info(f'Got reconnected to {self.nc.connected_url.netloc}') + + async def error_cb(e): + logger.info(f'There was an error: {e}') + + async def closed_cb(): + logger.info('Connection is closed') + await self.nc.connect( servers=[self.nats_url], token=self.nats_auth_token, @@ -18,6 +29,10 @@ async def connect(self): max_reconnect_attempts=-1, allow_reconnect=True, reconnect_time_wait=2, + disconnected_cb=disconnected_cb, + reconnected_cb=reconnected_cb, + error_cb=error_cb, + closed_cb=closed_cb, ) self.js = self.nc.jetstream() logger.info(f"Connected to NATS at {self.nats_url}")