public class MqttSubscribeSample
extends java.lang.Object
implements org.eclipse.paho.client.mqttv3.MqttCallback
Constructor and Description |
---|
MqttSubscribeSample() |
Modifier and Type | Method and Description |
---|---|
void |
connectionLost(java.lang.Throwable cause) |
void |
deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token) |
static void |
main(java.lang.String[] args)
The main entry point of the sample.
|
void |
messageArrived(java.lang.String topic,
org.eclipse.paho.client.mqttv3.MqttMessage message) |
void |
publish(java.lang.String topicName,
int qos,
byte[] payload)
Publish / send a message to an MQTT server
|
void |
subscribe()
Subscribe to a topic on an MQTT server
Once subscribed this method waits for the messages to arrive from the server
that match the subscription.
|
public MqttSubscribeSample() throws org.eclipse.paho.client.mqttv3.MqttException
org.eclipse.paho.client.mqttv3.MqttException
public static void main(java.lang.String[] args)
public void publish(java.lang.String topicName, int qos, byte[] payload) throws org.eclipse.paho.client.mqttv3.MqttException
topicName
- the name of the topic to publish toqos
- the quality of service to delivery the message at (0,1,2)payload
- the set of bytes to send to the MQTT serverorg.eclipse.paho.client.mqttv3.MqttException
public void subscribe() throws org.eclipse.paho.client.mqttv3.MqttException
topicName
- to subscribe to (can be wild carded)qos
- the maximum quality of service to receive messages at for this subscriptionorg.eclipse.paho.client.mqttv3.MqttException
public void connectionLost(java.lang.Throwable cause)
connectionLost
in interface org.eclipse.paho.client.mqttv3.MqttCallback
MqttCallback.connectionLost(Throwable)
public void deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token)
deliveryComplete
in interface org.eclipse.paho.client.mqttv3.MqttCallback
MqttCallback.deliveryComplete(IMqttDeliveryToken)
public void messageArrived(java.lang.String topic, org.eclipse.paho.client.mqttv3.MqttMessage message) throws org.eclipse.paho.client.mqttv3.MqttException
messageArrived
in interface org.eclipse.paho.client.mqttv3.MqttCallback
org.eclipse.paho.client.mqttv3.MqttException
MqttCallback.messageArrived(String, MqttMessage)