How can I track connected clients if my system account misses a connection event? #5768
-
I can track client connection changes to a NATS server with: client.Subscribe("$SYS.ACCOUNT.*.CONNECT", func(m *nats.Msg) {
fmt.Println("connected", string(m.Subject))
})
client.Subscribe("$SYS.ACCOUNT.*.DISCONNECT", func(m *nats.Msg) {
fmt.Println("connected", string(m.Subject))
}) However, if my server misses an event during redeployments, I'd like to be able to query the NATS server for currently connected clients on startup in order to evaluate an "online" status for a user interface. I'm prototyping using NATS with IoT devices and want to keep track of which devices are online. Can I query the server for connections? I know I can do this with the monitoring endpoint. But perhaps this can also be performed with the system account? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It looks like I can use serverID := client.ConnectedServerId()
msg, _ = client.Request(fmt.Sprintf("$SYS.REQ.SERVER.%s.CONNZ", serverID), nil, 5*time.Second)
fmt.Println(subject, "message:", string(msg.Subject), string(msg.Data)) My two follow up questions to this are:
|
Beta Was this translation helpful? Give feedback.
It looks like I can use
$SYS.REQ.SERVER.<server ID>.CONNZ
.My two follow up questions to this are:
$SYS.REQ.SERVER.<server ID>.CONNZ
for a single server or does it monitor the entire cluster for a multi-server setup?