Skip to content

Commit

Permalink
idk3
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixTJDietrich committed Aug 17, 2024
1 parent 03a0ad9 commit 0560eb7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion server/webhook-ingest/app/nats_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@
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()
self.nats_url = nats_url
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,
Expand All @@ -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}")
Expand Down

0 comments on commit 0560eb7

Please sign in to comment.