add type hints num accounts message

Signed-off-by: R.I.Pienaar <rip@devco.net>
This commit is contained in:
R.I.Pienaar
2020-10-19 11:56:49 +02:00
parent 923335e52d
commit ec606ebed2

View File

@@ -134,6 +134,7 @@ const DisconnectEventMsgType = "io.nats.server.advisory.v1.client_disconnect"
// a given account when the number of connections changes. It will also HB
// updates in the absence of any changes.
type AccountNumConns struct {
TypedEvent
Server ServerInfo `json:"server"`
Account string `json:"acc"`
Conns int `json:"conns"`
@@ -141,6 +142,8 @@ type AccountNumConns struct {
TotalConns int `json:"total_conns"`
}
const AccountNumConnsMsgType = "io.nats.server.advisory.v1.account_connections"
// accNumConnsReq is sent when we are starting to track an account for the first
// time. We will request others send info to us about their local state.
type accNumConnsReq struct {
@@ -1164,10 +1167,16 @@ func (s *Server) sendAccConnsUpdate(a *Account, subj ...string) {
return
}
// Build event with account name and number of local clients and leafnodes.
eid := s.nextEventID()
a.mu.Lock()
s.mu.Unlock()
localConns := a.numLocalConnections()
m := &AccountNumConns{
TypedEvent: TypedEvent{
Type: AccountNumConnsMsgType,
ID: eid,
Time: time.Now().UTC(),
},
Account: a.Name,
Conns: localConns,
LeafNodes: a.numLocalLeafNodes(),