public abstract class Mqtt extends Object implements org.eclipse.paho.client.mqttv3.MqttCallback
| Modifier and Type | Field and Description |
|---|---|
protected Object |
incomingLock |
| Constructor and Description |
|---|
Mqtt(MqttConnection mqttConnection,
IotHubListener listener,
MqttMessageListener messageListener,
String connectionId,
Map<Integer,Message> unacknowledgedSentMessages,
String deviceId)
Constructor to instantiate mqtt broker connection.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
connect()
Method to connect to mqtt broker connection.
|
void |
connectionLost(Throwable throwable)
Event fired when the connection with the MQTT broker is lost.
|
void |
deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken iMqttDeliveryToken)
Event fired when the message arrived on the MQTT broker.
|
protected void |
disconnect()
Method to disconnect to mqtt broker connection.
|
void |
messageArrived(String topic,
org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage)
Event fired when the message arrived on the MQTT broker.
|
org.apache.commons.lang3.tuple.Pair<String,byte[]> |
peekMessage() |
protected void |
publish(String publishTopic,
Message message)
Method to publish to mqtt broker connection.
|
IotHubTransportMessage |
receive()
Method to receive messages on mqtt broker connection.
|
protected boolean |
sendMessageAcknowledgement(int messageId)
Attempts to send ack for the provided message.
|
protected void |
subscribe(String topic)
Method to subscribe to mqtt broker connection.
|
protected final Object incomingLock
public Mqtt(MqttConnection mqttConnection, IotHubListener listener, MqttMessageListener messageListener, String connectionId, Map<Integer,Message> unacknowledgedSentMessages, String deviceId) throws IllegalArgumentException
mqttConnection - the connection to uselistener - the listener to be called back upon connection established/lost and upon a message being deliveredmessageListener - the listener to be called back upon a message arrivingconnectionId - the id of the connectiondeviceId - the Id of the device this connection belongs toIllegalArgumentException - if the provided mqttConnection is nullprotected void connect()
throws TransportException
TransportException - if failed to establish the mqtt connection.protected void disconnect()
throws TransportException
TransportException - if failed to ends the mqtt connection.protected void publish(String publishTopic, Message message) throws TransportException
publishTopic - the topic to publish on mqtt broker connection.message - the message to publish.TransportException - if sas token has expired, if connection hasn't been established yet, or if Paho throws
for any other reasonprotected void subscribe(String topic) throws TransportException
topic - the topic to subscribe on mqtt broker connection.TransportException - if failed to subscribe the mqtt topic.IllegalArgumentException - if topic is nullpublic IotHubTransportMessage receive() throws TransportException
nullTransportException - if failed to receive mqtt message.public void connectionLost(Throwable throwable)
connectionLost in interface org.eclipse.paho.client.mqttv3.MqttCallbackthrowable - Reason for losing the connection.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 org.apache.commons.lang3.tuple.Pair<String,byte[]> peekMessage()
protected boolean sendMessageAcknowledgement(int messageId)
throws TransportException
messageId - The message id to send the ack forTransportException - if an exception occurs when sending the ackCopyright © 2020. All rights reserved.