Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class MqttOptions

  1. Object
  2. MqttOptions
Everything an MqttClient needs to open and identify a connection. The setters return this.

Constructors

public MqttOptions(String uri, String clientId)Creates options.

Methods

public String getUri()The broker URI.
public String getClientId()The client identifier.
public boolean isCleanSession()Whether the broker should discard any session state of this client id.
public MqttOptions cleanSession(boolean cleanSession)Sets the clean session flag (default true).
public int getKeepAliveSeconds()The keep alive interval in seconds; 0 disables it.
public MqttOptions keepAliveSeconds(int seconds)Sets the keep alive interval in seconds (default 60, 0 to 65535).
public String getUsername()The user name, or null.
public byte[] getPassword()The password bytes, or null.
public MqttOptions credentials(String username, byte[] password)Sets the credentials.
public MqttOptions will(String topic, byte[] payload, int qos, boolean retain)Sets the will the broker publishes if this client vanishes.
public String getWillTopic()The will topic, or null.
public byte[] getWillPayload()The will payload, or null when there is no will.
public int getWillQos()The will QoS.
public boolean isWillRetain()The will retain flag.
public int getConnectTimeoutMillis()The time allowed for the transport to open and the broker to answer the CONNECT, in milliseconds.
public MqttOptions connectTimeoutMillis(int millis)Sets the connect timeout in milliseconds (default 15000).
public int getMaxPacketSize()The largest packet, in bytes after the fixed header, the client accepts.
public MqttOptions maxPacketSize(int bytes)Sets the largest incoming packet accepted (default 1 MiB, at most the protocol’s 268435455).

Inherited methods

Constructor details

MqttOptions

public MqttOptions(String uri, String clientId)
Creates options.

Parameters

uri String
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 String
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 String
the user name, or null for none
password byte[]
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 String
the will topic, or null to clear the will
payload byte[]
the will message
qos int
0 or 1
retain boolean
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.