Class MqttClient
java.lang.Object
de.iip_ecosphere.platform.transport.spring.binder.mqttv5.MqttClient
public class MqttClient extends Object
A central MQTT client for all binders to reduce resource usage. Typically, different binders subscribe to different
topics.
Partially public for testing. Initial implementation, not optimized.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMqttClient.ArrivedCallbackCalled when a message for a topic arrives.private static classMqttClient.CallbackThe internal MQTT reception callback. -
Field Summary
Fields Modifier and Type Field Description private static MqttClient.Callbackcallbackprivate static org.eclipse.paho.mqttv5.client.MqttAsyncClientclientprivate static MqttConfigurationconfigurationprivate static org.slf4j.LoggerLOGGERprivate static de.iip_ecosphere.platform.transport.connectors.basics.MqttQoSqos -
Constructor Summary
Constructors Constructor Description MqttClient() -
Method Summary
Modifier and Type Method Description (package private) static voidcreateClient(MqttConfiguration config)Creates the client based on a given MQTT client configuration.(package private) static voidsend(String topic, byte[] payload)Sendspayloadtotopic.static voidstopClient()Stops the client.(package private) static booleansubscribeTo(String topic, MqttClient.ArrivedCallback arrivedCallback)(package private) static booleanunsubscribeFrom(String topic)(package private) static voidwaitForCompletion(org.eclipse.paho.mqttv5.client.IMqttToken token)Waits for completion until thetokenis processed.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
client
private static org.eclipse.paho.mqttv5.client.MqttAsyncClient client -
configuration
-
callback
-
qos
private static de.iip_ecosphere.platform.transport.connectors.basics.MqttQoS qos
-
-
Constructor Details
-
MqttClient
public MqttClient()
-
-
Method Details
-
createClient
Creates the client based on a given MQTT client configuration.- Parameters:
config- the MQTT configuration to take the connection information from
-
stopClient
public static 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
static void waitForCompletion(org.eclipse.paho.mqttv5.client.IMqttToken token) throws org.eclipse.paho.mqttv5.common.MqttExceptionWaits for completion until thetokenis processed.- Parameters:
token- the token- Throws:
org.eclipse.paho.mqttv5.common.MqttException- in case that processing of the token fails
-