Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Question

When is the onConnectionLost and onServerInitiatedDisconnect event are triggered in HiveMQ Extension SDK?

Answer

onConnectionLost is called for the following reasons:

  1. The broker detects an I/O error or network failure.

  2. The client fails to communicate within the defined Keep Alive period.

  3. The client does not send a DISCONNECT packet before it closes the network connection.

onServerInitiatedDisconnect is called for the following reasons:

  1. The broker closes the network connection because of a protocol error.

  2. When

...

  1. a Client Take-Over happens.

  2. Client disconnected from the

...

  1. 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".