Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class MqttOptions
- Object
- 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
Inherited methods
Constructor details
MqttOptions
public MqttOptions(String uri, String clientId)Creates options.
Parameters
uriStringtcp://host[:port](default port 1883),ws://host[:port]/pathorwss://host[:port]/path, the last two over a WebSocket with themqttsubprotocolclientIdString- 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
usernameString- the user name, or null for none
passwordbyte[]- 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
topicString- the will topic, or null to clear the will
payloadbyte[]- the will message
qosint- 0 or 1
retainboolean- 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.