Skip to content

Commit

Permalink
adds debug output for connection state changes (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
autodidaddict authored Jul 3, 2024
1 parent f8cce65 commit 4881817
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions internal/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ func (n *Node) init() error {
n.log.Info("Established node NATS connection", slog.String("servers", n.opts.Servers))
}

n.nc.SetDisconnectErrHandler(n.ncDisconnectErrorHandler)
n.nc.SetReconnectHandler(n.ncReconnectedHandler)
n.nc.SetErrorHandler(n.ncErrorHandler)
n.nc.SetClosedHandler(n.ncClosedHandler)

n.manager, _err = NewWorkloadManager(
n.ctx,
n.cancelF,
Expand Down Expand Up @@ -304,6 +309,30 @@ func (n *Node) init() error {
return err
}

func (n *Node) ncDisconnectErrorHandler(conn *nats.Conn, err error) {
n.log.Error("NATS connection disconnected",
slog.Any("error", err),
slog.String("connection", conn.Opts.Name),
)
}

func (n *Node) ncReconnectedHandler(conn *nats.Conn) {
n.log.Info("NATS connection re-established")
}

func (n *Node) ncErrorHandler(conn *nats.Conn, _ *nats.Subscription, err error) {
n.log.Error("NATS error",
slog.Any("error", err),
slog.String("connection", conn.Opts.Name),
)
}

func (n *Node) ncClosedHandler(conn *nats.Conn) {
n.log.Info("NATS connection closed",
slog.String("connection", conn.Opts.Name),
)
}

func (n *Node) startPublicNATS() error {
if n.config.PublicNATSServer == nil {
// no-op
Expand Down

0 comments on commit 4881817

Please sign in to comment.