Skip to content

Commit

Permalink
feat: add name to NATS connections
Browse files Browse the repository at this point in the history
This facilitates debugging.
  • Loading branch information
smlx committed Mar 16, 2022
1 parent 7d2c639 commit 2907d76
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/ssh-portal/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (cmd *ServeCmd) Run(log *zap.Logger) error {
defer stop()
// get nats server connection
nconn, err := nats.Connect(cmd.NATSServer,
nats.Name("ssh-portal"),
// exit on connection close
nats.ClosedHandler(func(_ *nats.Conn) {
log.Error("nats connection closed")
Expand Down
3 changes: 2 additions & 1 deletion internal/sshportalapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ func ServeNATS(ctx context.Context, stop context.CancelFunc, log *zap.Logger,
wg.Add(1)
// connect to NATS server
nconn, err := nats.Connect(natsURL,
nats.Name("ssh-portal-api"),
// synchronise exiting ServeNATS()
nats.ClosedHandler(func(_ *nats.Conn) {
log.Error("nats connection closed")
// synchronise exiting ServeNATS()
stop()
wg.Done()
}),
Expand Down

0 comments on commit 2907d76

Please sign in to comment.