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
  • Field Details

  • Constructor Details

  • Method Details

    • createClient

      static void createClient​(MqttConfiguration config)
      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

      static boolean subscribeTo​(String topic, MqttClient.ArrivedCallback arrivedCallback)
      Subscribes to topic if topic is not blacklisted by MqttConfiguration.isFilteredTopic(String).
      Parameters:
      topic - the topic to unsubscribe from
      arrivedCallback - the callback to be called when a message arrived
      Returns:
      true if done/successful, false else
    • unsubscribeFrom

      static boolean unsubscribeFrom​(String topic)
      Unsubscribes from topic if topic is not blacklisted by MqttConfiguration.isFilteredTopic(String).
      Parameters:
      topic - the topic to unsubscribe from
      Returns:
      true if done/successful, false else
    • send

      static void send​(String topic, byte[] payload)
      Sends payload to topic.
      Parameters:
      topic - the topic to send to
      payload - the payload to send
    • waitForCompletion

      static void waitForCompletion​(org.eclipse.paho.mqttv5.client.IMqttToken token) throws org.eclipse.paho.mqttv5.common.MqttException
      Waits for completion until the token is processed.
      Parameters:
      token - the token
      Throws:
      org.eclipse.paho.mqttv5.common.MqttException - in case that processing of the token fails