Question
When is the onConnectionLost
and onServerInitiatedDisconnect
event are triggered in HiveMQ Extension SDK?
Answer
onConnectionLost
is called for the following reasons:
The broker detects an I/O error or network failure.
The client fails to communicate within the defined Keep Alive period.
The client does not send a DISCONNECT packet before it closes the network connection.
onServerInitiatedDisconnect
is called for the following reasons:
The broker closes the network connection because of a protocol error.
When
...
a Client Take-Over happens.
Client disconnected from the
...
Control Center or by REST API.
Note that The onConnectionLost
is never called for a client that is disconnected because of the session take over Client Take-Over because this disconnect is initiated by the broker => onServerInitiatedDisconnect
.
Hint
FYI clientService.isClientConnected(clientId)
will always give you the status of the client is : connected or not connected.
If the client is connected with clean start cleanStart=false
and its session still exists before client take over the Client Take-Over then the output will be “connected” "connected
" else the output will be “disconnected”"disconnected
".