@Service
public class MQTTService
extends java.lang.Object
implements org.eclipse.paho.client.mqttv3.MqttCallback
Constructor and Description |
---|
MQTTService() |
Modifier and Type | Method and Description |
---|---|
boolean |
addEventListener(java.lang.String subTopic,
MQTTEventListener listener)
Adds listener for specified subtopic for MQTT messages coming from devices.
|
void |
connectionLost(java.lang.Throwable cause) |
void |
deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token) |
void |
messageArrived(java.lang.String topic,
org.eclipse.paho.client.mqttv3.MqttMessage message) |
void |
sendMessage(java.util.UUID deviceId,
java.lang.String subTopic,
byte[] payload)
Sends a MQTT message.
|
void |
sendMessage(java.util.UUID deviceId,
java.lang.String subTopic,
java.lang.String payload)
Sends a MQTT message.
|
public boolean addEventListener(java.lang.String subTopic, MQTTEventListener listener)
subTopic
- subtopic to subscribe tolistener
- callback handling incoming messagepublic void connectionLost(java.lang.Throwable cause)
connectionLost
in interface org.eclipse.paho.client.mqttv3.MqttCallback
public void messageArrived(java.lang.String topic, org.eclipse.paho.client.mqttv3.MqttMessage message)
messageArrived
in interface org.eclipse.paho.client.mqttv3.MqttCallback
public void sendMessage(java.util.UUID deviceId, java.lang.String subTopic, byte[] payload) throws org.eclipse.paho.client.mqttv3.MqttException
deviceId
- UUID to send the message tosubTopic
- subtopic to use for communication with the devicepayload
- message contentorg.eclipse.paho.client.mqttv3.MqttException
- when there is a problem with storing the message or for other errors
encountered while publishing the messagepublic void sendMessage(java.util.UUID deviceId, java.lang.String subTopic, java.lang.String payload) throws org.eclipse.paho.client.mqttv3.MqttException
deviceId
- UUID to send the message tosubTopic
- subtopic to use for communication with the devicepayload
- message contentorg.eclipse.paho.client.mqttv3.MqttException
- when there is a problem with storing the message or for other errors
encountered while publishing the messagepublic void deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token)
deliveryComplete
in interface org.eclipse.paho.client.mqttv3.MqttCallback