Redningsselskapet / nestjs-plugins

Plugins for NestJS framework
ISC License
27 stars 22 forks source link

Connected hook #30

Closed kenguru33 closed 2 years ago

kenguru33 commented 2 years ago

Access the underlaying nats connection object through a connected hook.

Example code:

const logger = new Logger();
  const options: CustomStrategy = {
    strategy: new NatsJetStreamServer({
      connectionOptions: {
        name: 'myservice-listener',
        connectedHook: async (nc) => {
          logger.log('Connected to ' + nc.getServer());
          for await (const s of nc.status()) {
            if (s.type == DebugEvents.PingTimer) {
              console.log('We got ping timer attempt: ' + s.data);
            }
          }
        },
      },