public class DeviceClient extends AbstractClient implements org.eclipse.paho.client.mqttv3.MqttCallbackExtended
| Modifier and Type | Field and Description |
|---|---|
protected Map<Class,CommandCallback> |
commandCallbacks |
protected Map<Class,MessageCodec> |
messageCodecs |
protected Map<String,MessageCodec> |
messageCodecsByFormat |
CLIENT_ID_DELIMITER, config, DEFAULT_ACTION_TIMEOUT, DEFAULT_DISCONNECTED_BUFFER_SIZE, DEFAULT_MAX_CONNECT_ATTEMPTS, DEFAULT_MAX_INFLIGHT_MESSAGES, DEFAULT_MESSAGING_QOS, disconnectRequested, gson, messageCount, mqttAsyncClient, mqttCallback, mqttClient, mqttClientOptions, persistence| Constructor and Description |
|---|
DeviceClient() |
DeviceClient(DeviceConfig config)
Create a device client for the IBM Watson IoT Platform.
|
| Modifier and Type | Method and Description |
|---|---|
void |
connect()
Connects the application to IBM Watson IoT Platform and retries when there is an exception.
This method does not retry when the following exceptions occur. |
void |
connectComplete(boolean reconnect,
String serverURI) |
void |
connectionLost(Throwable e)
Simply log error when connection is lost
|
void |
deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token)
A completed deliver does not guarantee that the message is received by the service
because devices send messages with Quality of Service (QoS) 0.
|
void |
messageArrived(String topic,
org.eclipse.paho.client.mqttv3.MqttMessage msg)
The Device client does not currently support subscriptions.
|
boolean |
publishEvent(String eventId,
Object data) |
boolean |
publishEvent(String eventId,
Object data,
int qos)
Publish data to the IBM Watson IoT Platform.
|
protected void |
reconnect() |
void |
registerCodec(MessageCodec codec) |
void |
registerCommandCallback(CommandCallback callback) |
close, configureMqttClient, disconnect, getConfig, isConnected, toStringprotected Map<Class,MessageCodec> messageCodecs
protected Map<String,MessageCodec> messageCodecsByFormat
protected Map<Class,CommandCallback> commandCallbacks
public DeviceClient(DeviceConfig config) throws Exception
config - Configuration object for the clientException - When there is a failure in parsing the properties passedpublic void connect()
throws org.eclipse.paho.client.mqttv3.MqttException,
KeyManagementException,
NoSuchAlgorithmException
Connects the application to IBM Watson IoT Platform and retries when there is an exception.
This method does not retry when the following exceptions occur.
connect in class AbstractClientorg.eclipse.paho.client.mqttv3.MqttException - One or more credentials are wrongNoSuchAlgorithmException - TLS issuesKeyManagementException - TLS issuesprotected void reconnect()
throws org.eclipse.paho.client.mqttv3.MqttException,
KeyManagementException,
NoSuchAlgorithmException
org.eclipse.paho.client.mqttv3.MqttExceptionKeyManagementExceptionNoSuchAlgorithmExceptionpublic boolean publishEvent(String eventId, Object data, int qos)
eventId - object of String which denotes eventdata - Payload dataqos - Quality of Service, in int - can have values 0,1,2public void connectionLost(Throwable e)
connectionLost in interface org.eclipse.paho.client.mqttv3.MqttCallbackpublic void deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token)
deliveryComplete in interface org.eclipse.paho.client.mqttv3.MqttCallbacktoken - MQTT delivery tokenpublic void messageArrived(String topic, org.eclipse.paho.client.mqttv3.MqttMessage msg)
messageArrived in interface org.eclipse.paho.client.mqttv3.MqttCallbackpublic void connectComplete(boolean reconnect,
String serverURI)
connectComplete in interface org.eclipse.paho.client.mqttv3.MqttCallbackExtendedpublic void registerCodec(MessageCodec codec)
public void registerCommandCallback(CommandCallback callback)
Copyright © 2019. All rights reserved.