Allow Broker DisConnect connections by ClientId (#135)

* Allow Broker DisConnect connections by ClientId

* Allow Broker DisConnect connections by ClientId
This commit is contained in:
ZhangJian He
2022-01-05 11:15:45 +08:00
committed by GitHub
parent 878e7fce3f
commit ab117be4a8
3 changed files with 16 additions and 2 deletions

View File

@@ -255,6 +255,18 @@ func (b *Broker) StartClusterListening() {
}
}
func (b *Broker) DisConnClientByClientId(clientId string) {
cli, loaded := b.clients.LoadAndDelete(clientId)
if !loaded {
return
}
conn, success := cli.(*client)
if !success {
return
}
conn.Close()
}
func (b *Broker) handleConnection(typ int, conn net.Conn) {
//process connect packet
packet, err := packets.ReadPacket(conn)

View File

@@ -11,8 +11,8 @@ func InitHTTPMoniter(b *Broker) {
clientid := c.Param("clientid")
cli, ok := b.clients.Load(clientid)
if ok {
conn, succss := cli.(*client)
if succss {
conn, success := cli.(*client)
if success {
conn.Close()
}
}