public class MQTTHelper.MQTTClientWrapper
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
(package private) org.eclipse.paho.client.mqttv3.MqttConnectOptions |
_connOpts
Connection options for the current MQTT connection
|
| Constructor and Description |
|---|
MQTTClientWrapper(jdk.nashorn.api.scripting.ScriptObjectMirror currentObj,
int port,
java.lang.String host,
java.lang.String clientId,
boolean rawBytes)
This constructor creates one Paho MQTT client inside using given parameters.
|
| Modifier and Type | Method and Description |
|---|---|
void |
end()
Disconnect from the broker server and close (i.e. return all allocated resources) the client.
|
boolean |
isConnected()
Return whether the client is connected to a broker server.
|
void |
publish(java.lang.String topic,
java.lang.Object message,
java.lang.Integer qos,
boolean retain)
Publish an MQTT message to subscribers listening to the topic.
|
void |
start()
Start connection between the client and the broker server.
|
void |
subscribe(java.lang.String topic,
int qos)
Subscribe a topic using the given maximum QoS level.
|
void |
unsubscribe(java.lang.String topic)
Unsubscribe a topic.
|
org.eclipse.paho.client.mqttv3.MqttConnectOptions _connOpts
public MQTTClientWrapper(jdk.nashorn.api.scripting.ScriptObjectMirror currentObj,
int port,
java.lang.String host,
java.lang.String clientId,
boolean rawBytes)
throws org.eclipse.paho.client.mqttv3.MqttException
currentObj - The JavaScript instance of the WebSocket.port - The port number of the broker server.host - The host name of the broker server.clientId - The id of the client, whiich is passed to MqttAsyncClient();rawBytes - True if the payload is raw bytes.org.eclipse.paho.client.mqttv3.MqttExceptionpublic void start()
throws org.eclipse.paho.client.mqttv3.MqttSecurityException,
org.eclipse.paho.client.mqttv3.MqttException
org.eclipse.paho.client.mqttv3.MqttSecurityExceptionorg.eclipse.paho.client.mqttv3.MqttExceptionpublic void publish(java.lang.String topic,
java.lang.Object message,
java.lang.Integer qos,
boolean retain)
throws org.eclipse.paho.client.mqttv3.MqttException,
IllegalActionException
topic - The topic to which to publish.message - The message sent to subscribers.qos - The QoS level of the message. (0: At most once, 1: At least once, 2: Exactly once)retain - Whether the sever should hold on the message after it has been delivered to
current subscribers so that a newly incoming subscriber can receive the message later.org.eclipse.paho.client.mqttv3.MqttException - If the publish fails.IllegalActionExceptionpublic void subscribe(java.lang.String topic,
int qos)
throws org.eclipse.paho.client.mqttv3.MqttException
topic - The topic which the client will subscribe.qos - The maximum QoS at which to subscribe. Messages published at
a lower quality of service will be received at the published QoS. Messages published
at a higher quality of service will be received using the QoS specified on the subscribe.org.eclipse.paho.client.mqttv3.MqttExceptionpublic void unsubscribe(java.lang.String topic)
throws org.eclipse.paho.client.mqttv3.MqttException
topic - The topic which the client will unsubscribe.org.eclipse.paho.client.mqttv3.MqttExceptionpublic void end()
throws org.eclipse.paho.client.mqttv3.MqttException
org.eclipse.paho.client.mqttv3.MqttExceptionpublic boolean isConnected()