java.lang.Object
de.iip_ecosphere.platform.transport.spring.binder.hivemqv3.HivemqV3Client

@Component public class HivemqV3Client extends Object
A HiveMq 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
  • Field Details

    • LOGGER

      private static final de.iip_ecosphere.platform.support.logging.Logger LOGGER
    • lastInstance

      private static HivemqV3Client lastInstance
    • client

      private com.hivemq.client.mqtt.mqtt3.Mqtt3AsyncClient client
    • configuration

      private HivemqV3Configuration configuration
    • qos

      private com.hivemq.client.mqtt.datatypes.MqttQos qos
    • topics

      private Set<String> topics
  • Constructor Details

    • HivemqV3Client

      public HivemqV3Client()
      Creates and registers an instance.
  • Method Details

    • getLastInstance

      public static HivemqV3Client getLastInstance()
      Returns the last instance created for this class. [testing]
      Returns:
      the last instance
    • getConfiguration

      public HivemqV3Configuration getConfiguration()
      Returns the actual configuration. [for testing]
      Returns:
      the configuration, may be null
    • createClient

      public void createClient(HivemqV3Configuration config)
      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

      boolean subscribeTo(String topic, HivemqV3Client.ArrivedCallback arrivedCallback)
      Subscribes to topic if topic is not blacklisted by HivemqV3Configuration.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

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

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