Class MqttOptions

java.lang.Object
com.codename1.io.mqtt.MqttOptions

public final class MqttOptions extends Object
Everything an MqttClient needs to open and identify a connection. The setters return this.
  • Constructor Details

    • MqttOptions

      public MqttOptions(String uri, String clientId)

      Creates options.

      Parameters
      • uri: tcp://host[:port] (default port 1883), ws://host[:port]/path or wss://host[:port]/path, the last two over a WebSocket with the mqtt subprotocol

      • clientId: the client identifier; may be empty only with a clean session, in which case the broker assigns one

  • Method Details

    • getUri

      public String getUri()
      The broker URI.
    • getClientId

      public String getClientId()
      The client identifier.
    • isCleanSession

      public boolean isCleanSession()
      Whether the broker should discard any session state of this client id.
    • cleanSession

      public MqttOptions cleanSession(boolean cleanSession)
      Sets the clean session flag (default true). With false, the client keeps unacknowledged QoS 1 publishes across a reconnect and re-sends them with the DUP flag.
    • getKeepAliveSeconds

      public int getKeepAliveSeconds()
      The keep alive interval in seconds; 0 disables it.
    • keepAliveSeconds

      public MqttOptions keepAliveSeconds(int seconds)
      Sets the keep alive interval in seconds (default 60, 0 to 65535).
    • getUsername

      public String getUsername()
      The user name, or null.
    • getPassword

      public byte[] getPassword()
      The password bytes, or null. The array is not copied.
    • credentials

      public MqttOptions credentials(String username, byte[] password)

      Sets the credentials. MQTT 3.1.1 allows a password only with a user name.

      Parameters
      • username: the user name, or null for none

      • password: the password, or null for none

    • will

      public MqttOptions will(String topic, byte[] payload, int qos, boolean retain)

      Sets the will the broker publishes if this client vanishes.

      Parameters
      • topic: the will topic, or null to clear the will

      • payload: the will message

      • qos: 0 or 1

      • retain: whether the broker retains the will

    • getWillTopic

      public String getWillTopic()
      The will topic, or null.
    • getWillPayload

      public byte[] getWillPayload()
      The will payload, or null when there is no will.
    • getWillQos

      public int getWillQos()
      The will QoS.
    • isWillRetain

      public boolean isWillRetain()
      The will retain flag.
    • getConnectTimeoutMillis

      public int getConnectTimeoutMillis()
      The time allowed for the transport to open and the broker to answer the CONNECT, in milliseconds.
    • connectTimeoutMillis

      public MqttOptions connectTimeoutMillis(int millis)
      Sets the connect timeout in milliseconds (default 15000).
    • getMaxPacketSize

      public int getMaxPacketSize()
      The largest packet, in bytes after the fixed header, the client accepts.
    • maxPacketSize

      public MqttOptions maxPacketSize(int bytes)
      Sets the largest incoming packet accepted (default 1 MiB, at most the protocol's 268435455). A larger one fails the connection.