Class MqttClient
java.lang.Object
de.iip_ecosphere.platform.transport.spring.binder.mqttv3.MqttClient
A MQTT client for a single binder instance. Typically, different binders subscribe to different
topics.
Partially public for testing. Initial implementation, not optimized.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCalled when a message for a topic arrives.private static classThe internal MQTT reception callback. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate MqttClient.Callbackprivate org.eclipse.paho.client.mqttv3.MqttAsyncClientprivate MqttConfigurationprivate static MqttClientprivate static final de.iip_ecosphere.platform.support.logging.Loggerprivate de.iip_ecosphere.platform.transport.connectors.basics.MqttQoS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateClient(MqttConfiguration config) Creates the client based on a given MQTT client configuration.Returns the actual configuration.static MqttClientReturns the last instance created for this class.(package private) voidSendspayloadtotopic.voidStops the client.(package private) booleansubscribeTo(String topic, MqttClient.ArrivedCallback arrivedCallback) (package private) booleanunsubscribeFrom(String topic) (package private) voidwaitForCompletion(org.eclipse.paho.client.mqttv3.IMqttToken token) Waits for completion until thetokenis processed.
-
Field Details
-
LOGGER
private static final de.iip_ecosphere.platform.support.logging.Logger LOGGER -
lastInstance
-
client
private org.eclipse.paho.client.mqttv3.MqttAsyncClient client -
configuration
-
callback
-
qos
private de.iip_ecosphere.platform.transport.connectors.basics.MqttQoS qos
-
-
Constructor Details
-
MqttClient
public MqttClient()Creates and registers an instance.
-
-
Method Details
-
getLastInstance
Returns the last instance created for this class. [testing]- Returns:
- the last instance
-
getConfiguration
Returns the actual configuration. [for testing]- Returns:
- the configuration, may be null
-
createClient
Creates the client based on a given MQTT client configuration.- Parameters:
config- the MQTT configuration to take the connection information from
-
stopClient
public void stopClient()Stops the client. -
subscribeTo
- Parameters:
topic- the topic to unsubscribe fromarrivedCallback- the callback to be called when a message arrived- Returns:
trueif done/successful,falseelse
-
unsubscribeFrom
- Parameters:
topic- the topic to unsubscribe from- Returns:
trueif done/successful,falseelse
-
send
Sendspayloadtotopic.- Parameters:
topic- the topic to send topayload- the payload to send
-
waitForCompletion
void waitForCompletion(org.eclipse.paho.client.mqttv3.IMqttToken token) throws org.eclipse.paho.client.mqttv3.MqttException Waits for completion until thetokenis processed.- Parameters:
token- the token- Throws:
org.eclipse.paho.client.mqttv3.MqttException- in case that processing of the token fails
-