public class MqttConnection extends Object implements org.eclipse.paho.client.mqttv3.MqttCallback
| Constructor and Description |
|---|
MqttConnection(String hostname,
String clientId,
String userName,
String password,
SSLContext sslContext,
MqttListener listener,
boolean useWebSockets)
Constructor to create MqttAsync Client with Paho
|
| Modifier and Type | Method and Description |
|---|---|
void |
connect()
Connects to the MQTT broker
|
void |
connectionLost(Throwable throwable)
Event fired when the connection is lost on the MQTT broker
|
void |
deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken iMqttDeliveryToken)
Event fired when the message arrived on the MQTT broker.
|
void |
disconnect()
Disconnects from the MQTT broker
|
boolean |
isMqttConnected()
Return whether the MQTT broker is connected to the endpoint
|
void |
messageArrived(String topic,
org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage)
Event fired when the message arrived on the MQTT broker.
|
void |
publishMessage(MqttMessage message)
Sends a PUBLISH message to the MQTT broker
|
void |
publishMessage(String topic,
MqttQos qos,
byte[] message)
Sends a PUBLISH message to the MQTT broker
|
void |
subscribe(String topic,
MqttQos qos)
Send the SUBSCRIBE message to the MQTT broker
|
void |
unsubscribe(String topic)
Send the UNSUBSCRIBE message to the MQTT broker
|
public MqttConnection(String hostname, String clientId, String userName, String password, SSLContext sslContext, MqttListener listener, boolean useWebSockets) throws IOException
hostname - Uri to connect toclientId - Client Id to connect touserName - Usernamepassword - passwordsslContext - SSLContext for the connectionlistener - Mqtt listeneruseWebSockets - true to use Mqtt over web socketsIOException - is thrown if any of the parameters are null or empty or client cannot be instantiatedpublic boolean isMqttConnected()
public void connect()
throws IOException
IOException - if there is a Mqtt exception.public void disconnect()
throws IOException
IOException - if there is a Mqtt exception.public void publishMessage(String topic, MqttQos qos, byte[] message) throws IOException
topic - The topic of the messageqos - The QOS of the messagemessage - The message to be sentIOException - if there is a Mqtt exception.public void publishMessage(MqttMessage message) throws IOException
message - The message to be sentIOException - if there is a Mqtt exception.public void subscribe(String topic, MqttQos qos) throws IOException
topic - The topic of the messageqos - The QOS of the messageIOException - if there is a Mqtt exception.public void unsubscribe(String topic) throws IOException
topic - Name of the Topic to unsubscribe.IOException - if there is a Mqtt exception.public void messageArrived(String topic, org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage)
messageArrived in interface org.eclipse.paho.client.mqttv3.MqttCallbacktopic - the topic on which message arrived.mqttMessage - the message arrived on the Mqtt broker.public void deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken iMqttDeliveryToken)
deliveryComplete in interface org.eclipse.paho.client.mqttv3.MqttCallbackiMqttDeliveryToken - the MqttDeliveryToken for which the message was successfully sent.public void connectionLost(Throwable throwable)
connectionLost in interface org.eclipse.paho.client.mqttv3.MqttCallbackthrowable - the disconnection reason.Copyright © 2019. All rights reserved.