Class MqttConnectException

All Implemented Interfaces:
Serializable

public final class MqttConnectException extends MqttException
A connection attempt failed. A broker refusal carries its reason code; transport failures and deadline expiry carry a cause instead. An MQTT 5.0 broker can also explain its refusal in reasonString() and, with ReasonCode.USE_ANOTHER_SERVER or ReasonCode.SERVER_MOVED, name another server in serverReference(), which the client does not follow. Locally detected packet failures carry MqttProtocolException as their cause, leaving reasonCode() empty. An attempt that discarded a broker session without local state and then finds a session again, as MqttClient.connect() describes, fails with neither a reason code nor a cause, as does an attempt that MqttClient.disconnect() or MqttClient.close() withdraws. A failure while closing the connection that found the session is attached as a suppressed exception. If the client's TimerScheduler fails meanwhile, that failure is the cause instead, and the refusal is attached as a suppressed exception.
See Also:
  • Constructor Details

    • MqttConnectException

      public MqttConnectException(String message)
      A failure with neither a reason code nor a cause.
      Parameters:
      message - the detail message
    • MqttConnectException

      public MqttConnectException(String message, ReasonCode reasonCode)
      A broker refusal without an explanation or a server reference.
      Parameters:
      message - the detail message
      reasonCode - the broker's refusal reason
    • MqttConnectException

      public MqttConnectException(String message, ReasonCode reasonCode, @Nullable String reasonString, @Nullable String serverReference)
      A broker refusal with the explanation and the server reference that the broker sent, if any.
      Parameters:
      message - the detail message
      reasonCode - the broker's refusal reason
      reasonString - the broker's explanation, or null when it sent none
      serverReference - the server that the broker named, or null when it named none
    • MqttConnectException

      public MqttConnectException(String message, Throwable cause)
      A failure with a cause instead of a reason code, such as a transport failure or deadline expiry.
      Parameters:
      message - the detail message
      cause - the cause of the failure
  • Method Details

    • reasonCode

      public Optional<ReasonCode> reasonCode()
      Returns the broker's refusal reason, or empty when the attempt failed locally.
      Returns:
      the broker's refusal reason, or empty when the attempt failed locally
    • reasonString

      public Optional<String> reasonString()
      Returns the broker's explanation of its refusal for people diagnosing it, or empty when it sent none, as MQTT 3.1.1 brokers never do.
      Returns:
      the broker's explanation of its refusal for people diagnosing it, or empty when it sent none, as MQTT 3.1.1 brokers never do
    • serverReference

      public Optional<String> serverReference()
      Returns the server that the broker named for the client to use instead, or empty when it named none.
      Returns:
      the server that the broker named for the client to use instead, or empty when it named none