@DoNotImplement public interface MqttClientDisconnectedContext
| Modifier and Type | Method and Description |
|---|---|
@NotNull Throwable |
getCause()
Returns the cause for disconnection.
|
@NotNull MqttClientConfig |
getClientConfig() |
@NotNull MqttClientReconnector |
getReconnector() |
@NotNull MqttDisconnectSource |
getSource() |
@NotNull @NotNull MqttClientConfig getClientConfig()
@NotNull @NotNull MqttDisconnectSource getSource()
@NotNull @NotNull Throwable getCause()
This can be:
ConnectionFailedException if a connect
attempt failed
Mqtt3ConnAckException or Mqtt5ConnAckException (depending on the MQTT
version of the client) if the ConnAck message contained an error code, which means that the connect was
rejected
ConnectionClosedException if the
connection was closed without sending a Disconnect message (use getSource() to determine if the
server or the client closed the connection)
Mqtt3DisconnectException or Mqtt5DisconnectException (depending on the
MQTT version of the client) if the connection was closed with a Disconnect message (use getSource()
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();
});
@NotNull @NotNull MqttClientReconnector getReconnector()