com.supermap.messagequeue

Class MQTTClient



  • public class MQTTClient
    extends InternalHandle
    The MQTT client class, based on message bus of MQTT protocol.

    The use of theme subscription to achieve the mechanism of messaging,

    • Constructor Summary

      Constructors 
      Constructor and Description
      MQTTClient()
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      boolean create(java.lang.String uri, java.lang.String userName, java.lang.String password, java.lang.String clientID)
      Creates connection.
      void dispose()
      Destructor, release resource
      MQTTReturnMessage receiveMessage()
      Receive the message You need to perform this operation on a child thread
      void resume()
      Resume.
      boolean sendMessage(java.lang.String topic, java.lang.String message)
      Send a message
      boolean subscribe(java.lang.String topicName, int qos)
      Subscribes a topic.
      void suspend()
      Suspend.
      boolean unsubscribe(java.lang.String topicName)
      Cancels a topic of subscription.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MQTTClient

        public MQTTClient()
        Constructor
    • Method Detail

      • create

        public boolean create(java.lang.String uri,
                              java.lang.String userName,
                              java.lang.String password,
                              java.lang.String clientID)
        Creates connection.
        Parameters:
        uri - Service address
        userName - username
        password - user password
        clientID - Client ID
        Returns:
        Returns true if the creation succeeds, false otherwise
      • dispose

        public void dispose()
        Destructor, release resource
      • subscribe

        public boolean subscribe(java.lang.String topicName,
                                 int qos)
        Subscribes a topic.
        Parameters:
        topicName - Subject name
        qos - Message quality
        Returns:
        Returns true if the subscription succeeds, false otherwise
      • unsubscribe

        public boolean unsubscribe(java.lang.String topicName)
        Cancels a topic of subscription.
        Parameters:
        topicName - Subject name
        Returns:
        Returns whether or not to cancel successfully
      • sendMessage

        public boolean sendMessage(java.lang.String topic,
                                   java.lang.String message)
        Send a message
        Parameters:
        topic - Subject name
        message - Message content
        Returns:
        Returns true if sent successfully, false otherwise
      • receiveMessage

        public MQTTReturnMessage receiveMessage()
        Receive the message

        You need to perform this operation on a child thread

        Returns:
        Received message
      • resume

        public void resume()
        Resume.
      • suspend

        public void suspend()
        Suspend.