Package com.hivemq.client.mqtt.lifecycle
Interface MqttClientDisconnectedContext
- All Known Subinterfaces:
Mqtt3ClientDisconnectedContext,Mqtt5ClientDisconnectedContext
Provides context about the client that is now disconnected, the cause for disconnection and allows reconnecting.
- Since:
- 1.1
-
Method Summary
-
Method Details
-
getClientConfig
- Returns:
- the config of the client that is now disconnected.
-
getSource
- Returns:
- the source which triggered the disconnection.
-
getCause
Returns the cause for disconnection.This can be:
ConnectionFailedExceptionif a connect attempt failedMqtt3ConnAckExceptionorMqtt5ConnAckException(depending on the MQTT version of the client) if the ConnAck message contained an error code, which means that the connect was rejectedConnectionClosedExceptionif the connection was closed without sending a Disconnect message (usegetSource()to determine if the server or the client closed the connection)Mqtt3DisconnectExceptionorMqtt5DisconnectException(depending on the MQTT version of the client) if the connection was closed with a Disconnect message (usegetSource()to determine if the server, the user or the client sent the Disconnect message)
Example: You can use the following code to extract the Disconnect message:
TypeSwitch.when(context.getCause()).is(Mqtt5DisconnectException.class, disconnectException -> { Mqtt5Disconnect disconnect = disconnectException.getMqttMessage(); }).is(Mqtt3DisconnectException.class, disconnectException -> { Mqtt3Disconnect disconnect = disconnectException.getMqttMessage(); });- Returns:
- the cause for disconnection.
-
getReconnector
- Returns:
- the reconnector which can be used for reconnecting.
-