Class HivemqV5Client


  • @Component
    public class HivemqV5Client
    extends java.lang.Object
    A HiveMq client for all a single binder instance. Typically, different binders subscribe to different topics. Partially public for testing. Initial implementation, not optimized.
    Author:
    Holger Eichelberger, SSE
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • client

        private com.hivemq.client.mqtt.mqtt5.Mqtt5AsyncClient client
      • qos

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

        private java.util.Set<java.lang.String> topics
    • Constructor Detail

      • HivemqV5Client

        public HivemqV5Client()
        Creates and registers an instance.
    • Method Detail

      • getLastInstance

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

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

        public void createClient​(HivemqV5Configuration 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.
      • unsubscribeFrom

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

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