Package 

Interface IMqttServer


  • 
    public interface IMqttServer
    
                        

    Enables an android application to communicate with an MQTT server.

    • Method Detail

      • subscribe

         abstract void subscribe(String topic, IResultCallback callback)

        Subscribe to a topic.

        Parameters:
        topic - the topic to subscribe to, which can include wildcards.
        callback - optional listener that will be notified when subscribe hascompleted
      • subscribe

         abstract void subscribe(String topic, int qos, IResultCallback callback)

        Subscribe to a topic with qos.

        Parameters:
        topic - the topic to subscribe to, which can include wildcards.
        qos - the maximum quality of service at which to subscribe.
        callback - optional listener that will be notified when subscribe hascompleted
      • subscribe

         abstract void subscribe(Array<String> topicIds, IResultCallback callback)

        Subscribe topics to MQTT server.

        If you need to register a listener, please see registerMqttMessageParserListener

        Parameters:
        topicIds - Topic ids which you want to subscribe.
        callback - Callback whether the subscription is successful
      • subscribe

         abstract void subscribe(Array<String> topic, Array<int> qos, IResultCallback callback)

        Subscribes to multiple topics, each topic may include wildcards.

        Provides an optimized way to subscribe to multiple topics compared tosubscribing to each one individually.

        The registerMqttMessageParserListener method should be called beforethis method, otherwise any received messages will be discarded.

        If (@link MqttConnectOptions#setCleanSession(boolean)} was set to true,when connecting to the server, the subscription remains in place untileither:

        • The client disconnects
        • An unsubscribe method is called to unsubscribe the topic

        If (@link MqttConnectOptions#setCleanSession(boolean)} was set to false,when connecting to the server, the subscription remains in placeuntil either:

        • An unsubscribe method is called to unsubscribe the topic
        • The next time the client connects with cleanSession set to true

        With cleanSession set to false the MQTT server will store messageson behalf of the client when the client is not connected. The next timethe client connects with the same client ID the server willdeliver the stored messages to the client.

        The "topic filter" string is used when subscription may contain specialcharacters, which allows you to subscribe to multiple topics at once.

        Parameters:
        topic - one or more topics to subscribe to, which can includewildcards
        qos - the maximum quality of service to subscribe each topicat.Messages published at a lower quality of service will bereceived at the published QoS.
        callback - optional listener that will be notified when subscribe hascompleted
      • unSubscribe

         abstract void unSubscribe(String topic, IResultCallback callback)

        Requests the server unsubscribe the client from a topic.

        Parameters:
        topic - the topic to unsubscribe from.
        callback - optional listener that will be notified when unsubscribe hascompleted
      • publish

         abstract IMqttDeliveryToken publish(String topic, Array<byte> data, IResultCallback callback)

        Publishes a message to a topic on the server.

        Once this method has returned cleanly, the message has been accepted forpublication by the client and will be delivered on a background thread.In the event the connection fails or the client stops, Messages will bedelivered to the requested quality of service once the connection isre-established to the server on condition that:

        • The connection is re-established with the same clientID
        • The original connection was made with (@linkMqttConnectOptions#setCleanSession(boolean)} set to false
        • The connection is re-established with (@linkMqttConnectOptions#setCleanSession(boolean)} set to false
        • Depending when the failure occurs QoS 0 messages may not bedelivered.

        When building an application, the design of the topic tree should takeinto account the following principles of topic name syntax and semantics:

        • A topic must be at least one character long.
        • Topic names are case sensitive. For example, ACCOUNTS andAccounts are two different topics.
        • Topic names can include the space character. For example,Accountspayable is a valid topic.
        • A leading "/" creates a distinct topic. For example,/finance is different from finance. /financematches "+/+" and "/+", but not "+".
        • Do not include the null character (Unicode \x0000) in any topic.

        The following principles apply to the construction and content of a topictree:

        • The length is limited to 64k but within that there are no limits tothe number of levels in a topic tree.
        • There can be any number of root nodes; that is, there can be anynumber of topic trees.
        Parameters:
        topic - to deliver the message to, for example "finance/stock/ibm".
        data - to deliver to the server
        callback - optional listener that will be notified when message deliveryhas completed to the requested quality of service
      • publish

         abstract IMqttDeliveryToken publish(String topicId, Array<byte> data, int qos, boolean retained, IResultCallback callback)

        Publishes a message to a topic on the server.

        Parameters:
        topicId - to deliver the message to, for example "finance/stock/ibm".
        data - to deliver to the server
        qos - the Quality of Service to deliver the message at.
        retained - whether or not this message should be retained by the server.
        callback - optional listener that will be notified when message deliveryhas completed to the requested quality of service
      • publishDevice

         abstract void publishDevice(MqttControlBuilder builder, IResultCallback callback)

        Publish message to specified device to control it on mqtt server.

        Parameters:
        builder - MqttControlBuilder Control device message builder
        callback - Listener that will be notified when message deliveryhas completed to the requested quality of service
      • connect

         abstract void connect()

        Connects to an MQTT server and init MQTT config.

        It is recommended to call registerMqttCallback prior toconnecting in order that messages destined for the client can be acceptedas soon as the client is connected.

      • close

         abstract void close()

        Close the client. Releases all resource associated with the client. Afterthe client has been closed it cannot be reused. For instance attempts toconnect will fail.

      • justConnect

         abstract void justConnect()

        Just connects to an MQTT server. connect also initialize the configuration.

        Only call the justClose method can call this method.

        It is recommended to call registerMqttCallback prior toconnecting in order that messages destined for the client can be acceptedas soon as the client is connected.

      • justClose

         abstract void justClose()

        Just close connection, not releases all resource.If you need to reconnect, just call justConnect

      • isRealConnect

         abstract boolean isRealConnect()

        Determines if this client is currently connected to the server.

      • rawConnect

         abstract void rawConnect()

        Connects to an MQTT server , direct connect.

      • isSubscribe

         abstract boolean isSubscribe(String topicId)

        是否已经订阅