io.vertx.mqtt

## Interface MqttClient

-     public interface MqttClient

  An MQTT client

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `clientId()`
    `MqttClient` | `closeHandler(Handler<Void> closeHandler)` Set a handler that will be called when the connection with server is closed
    `MqttClient` | `connect(int port, String host, Handler<AsyncResult<MqttConnAckMessage>> connectHandler)` Connects to an MQTT server calling connectHandler after connection
    `MqttClient` | `connect(int port, String host, String serverName, Handler<AsyncResult<MqttConnAckMessage>> connectHandler)` Connects to an MQTT server calling connectHandler after connection
    `static MqttClient` | `create(Vertx vertx)` Return an MQTT client instance using the default options
    `static MqttClient` | `create(Vertx vertx, MqttClientOptions options)` Return an MQTT client instance
    `MqttClient` | `disconnect()` Disconnects from the MQTT server
    `MqttClient` | `disconnect(Handler<AsyncResult<Void>> disconnectHandler)` Disconnects from the MQTT server calling disconnectHandler after disconnection
    `MqttClient` | `exceptionHandler(Handler<Throwable> handler)` Set an exception handler for the client, that will be called when an error happens in internal netty structures.
    `boolean` | `isConnected()`
    `MqttClient` | `ping()` This method is needed by the client in order to avoid server closes the connection due to the keep alive timeout if client has no messages to send
    `MqttClient` | `pingResponseHandler(Handler<Void> pingResponseHandler)` Sets handler which will be called after PINGRESP packet receiving
    `MqttClient` | `publish(String topic, Buffer payload, io.netty.handler.codec.mqtt.MqttQoS qosLevel, boolean isDup, boolean isRetain)` Sends the PUBLISH message to the remote MQTT server
    `MqttClient` | `publish(String topic, Buffer payload, io.netty.handler.codec.mqtt.MqttQoS qosLevel, boolean isDup, boolean isRetain, Handler<AsyncResult<Integer>> publishSentHandler)` Sends the PUBLISH message to the remote MQTT server
    `MqttClient` | `publishCompletionHandler(Handler<Integer> publishCompletionHandler)` Sets handler which will be called each time publish is completed
    `MqttClient` | `publishHandler(Handler<MqttPublishMessage> publishHandler)` Sets handler which will be called each time server publish something to client
    `MqttClient` | `subscribe(Map<String,Integer> topics)` Subscribes to the topics with related QoS levels
    `MqttClient` | `subscribe(Map<String,Integer> topics, Handler<AsyncResult<Integer>> subscribeSentHandler)` Subscribes to the topic and adds a handler which will be called after the request is sent
    `MqttClient` | `subscribe(String topic, int qos)` Subscribes to the topic with a specified QoS level
    `MqttClient` | `subscribe(String topic, int qos, Handler<AsyncResult<Integer>> subscribeSentHandler)` Subscribes to the topic with a specified QoS level
    `MqttClient` | `subscribeCompletionHandler(Handler<MqttSubAckMessage> subscribeCompletionHandler)` Sets handler which will be called after SUBACK packet receiving
    `MqttClient` | `unsubscribe(String topic)` Unsubscribe from receiving messages on given topic
    `MqttClient` | `unsubscribe(String topic, Handler<AsyncResult<Integer>> unsubscribeSentHandler)` Unsubscribe from receiving messages on given topic
    `MqttClient` | `unsubscribeCompletionHandler(Handler<Integer> unsubscribeCompletionHandler)` Sets handler which will be called after UNSUBACK packet receiving

- - ### Method Detail

    - #### create

          static MqttClient create(Vertx vertx,
                                   MqttClientOptions options)

      Return an MQTT client instance
      Parameters:
        `vertx` - Vert.x instance
        `options` - MQTT client options
      Returns:
        MQTT client instance

    - #### create

          static MqttClient create(Vertx vertx)

      Return an MQTT client instance using the default options
      Parameters:
        `vertx` - Vert.x instance
      Returns:
        MQTT client instance

    - #### connect

          MqttClient connect(int port,
                             String host,
                             Handler<AsyncResult<MqttConnAckMessage>> connectHandler)

      Connects to an MQTT server calling connectHandler after connection
      Parameters:
        `port` - port of the MQTT server
        `host` - hostname/ip address of the MQTT server
        `connectHandler` - handler called when the asynchronous connect call ends
      Returns:
        current MQTT client instance

    - #### connect

          MqttClient connect(int port,
                             String host,
                             String serverName,
                             Handler<AsyncResult<MqttConnAckMessage>> connectHandler)

      Connects to an MQTT server calling connectHandler after connection
      Parameters:
        `port` - port of the MQTT server
        `host` - hostname/ip address of the MQTT server
        `serverName` - the SNI server name
        `connectHandler` - handler called when the asynchronous connect call ends
      Returns:
        current MQTT client instance

    - #### disconnect

          MqttClient disconnect()

      Disconnects from the MQTT server
      Returns:
        current MQTT client instance

    - #### disconnect

          MqttClient disconnect(Handler<AsyncResult<Void>> disconnectHandler)

      Disconnects from the MQTT server calling disconnectHandler after disconnection
      Parameters:
        `disconnectHandler` - handler called when asynchronous disconnect call ends
      Returns:
        current MQTT client instance

    - #### publish

          MqttClient publish(String topic,
                             Buffer payload,
                             io.netty.handler.codec.mqtt.MqttQoS qosLevel,
                             boolean isDup,
                             boolean isRetain)

      Sends the PUBLISH message to the remote MQTT server
      Parameters:
        `topic` - topic on which the message is published
        `payload` - message payload
        `qosLevel` - QoS level
        `isDup` - if the message is a duplicate
        `isRetain` - if the message needs to be retained
      Returns:
        current MQTT client instance

    - #### publish

          MqttClient publish(String topic,
                             Buffer payload,
                             io.netty.handler.codec.mqtt.MqttQoS qosLevel,
                             boolean isDup,
                             boolean isRetain,
                             Handler<AsyncResult<Integer>> publishSentHandler)

      Sends the PUBLISH message to the remote MQTT server
      Parameters:
        `topic` - topic on which the message is published
        `payload` - message payload
        `qosLevel` - QoS level
        `isDup` - if the message is a duplicate
        `isRetain` - if the message needs to be retained
        `publishSentHandler` - handler called after PUBLISH packet sent with packetid (not when QoS 0)
      Returns:
        current MQTT client instance

    - #### publishCompletionHandler

          MqttClient publishCompletionHandler(Handler<Integer> publishCompletionHandler)

      Sets handler which will be called each time publish is completed
      Parameters:
        `publishCompletionHandler` - handler called with the packetId
      Returns:
        current MQTT client instance

    - #### publishHandler

          MqttClient publishHandler(Handler<MqttPublishMessage> publishHandler)

      Sets handler which will be called each time server publish something to client
      Parameters:
        `publishHandler` - handler to call
      Returns:
        current MQTT client instance

    - #### subscribeCompletionHandler

          MqttClient subscribeCompletionHandler(Handler<MqttSubAckMessage> subscribeCompletionHandler)

      Sets handler which will be called after SUBACK packet receiving
      Parameters:
        `subscribeCompletionHandler` - handler to call. List inside is a granted QoS array
      Returns:
        current MQTT client instance

    - #### subscribe

          MqttClient subscribe(String topic,
                               int qos)

      Subscribes to the topic with a specified QoS level
      Parameters:
        `topic` - topic you subscribe on
        `qos` - QoS level
      Returns:
        current MQTT client instance

    - #### subscribe

          MqttClient subscribe(String topic,
                               int qos,
                               Handler<AsyncResult<Integer>> subscribeSentHandler)

      Subscribes to the topic with a specified QoS level
      Parameters:
        `topic` - topic you subscribe on
        `qos` - QoS level
        `subscribeSentHandler` - handler called after SUBSCRIBE packet sent with packetid
      Returns:
        current MQTT client instance

    - #### subscribe

          MqttClient subscribe(Map<String,Integer> topics)

      Subscribes to the topics with related QoS levels
      Parameters:
        `topics` - topics and related QoS levels to subscribe to
      Returns:
        current MQTT client instance

    - #### subscribe

          MqttClient subscribe(Map<String,Integer> topics,
                               Handler<AsyncResult<Integer>> subscribeSentHandler)

      Subscribes to the topic and adds a handler which will be called after the request is sent
      Parameters:
        `topics` - topics you subscribe on
        `subscribeSentHandler` - handler called after SUBSCRIBE packet sent with packetid
      Returns:
        current MQTT client instance

    - #### unsubscribeCompletionHandler

          MqttClient unsubscribeCompletionHandler(Handler<Integer> unsubscribeCompletionHandler)

      Sets handler which will be called after UNSUBACK packet receiving
      Parameters:
        `unsubscribeCompletionHandler` - handler to call with the packetid
      Returns:
        current MQTT client instance

    - #### unsubscribe

          MqttClient unsubscribe(String topic)

      Unsubscribe from receiving messages on given topic
      Parameters:
        `topic` - Topic you want to unsubscribe from
      Returns:
        current MQTT client instance

    - #### unsubscribe

          MqttClient unsubscribe(String topic,
                                 Handler<AsyncResult<Integer>> unsubscribeSentHandler)

      Unsubscribe from receiving messages on given topic
      Parameters:
        `topic` - Topic you want to unsubscribe from
        `unsubscribeSentHandler` - handler called after UNSUBSCRIBE packet sent
      Returns:
        current MQTT client instance

    - #### pingResponseHandler

          MqttClient pingResponseHandler(Handler<Void> pingResponseHandler)

      Sets handler which will be called after PINGRESP packet receiving
      Parameters:
        `pingResponseHandler` - handler to call
      Returns:
        current MQTT client instance

    - #### exceptionHandler

          MqttClient exceptionHandler(Handler<Throwable> handler)

      Set an exception handler for the client, that will be called when an error happens in internal netty structures. `io.netty.handler.codec.DecoderException` can be one of the cause
      Parameters:
        `handler` - the exception handler
      Returns:
        current MQTT client instance

    - #### closeHandler

          MqttClient closeHandler(Handler<Void> closeHandler)

      Set a handler that will be called when the connection with server is closed
      Parameters:
        `closeHandler` - handler to call
      Returns:
        current MQTT client instance

    - #### ping

          MqttClient ping()

      This method is needed by the client in order to avoid server closes the connection due to the keep alive timeout if client has no messages to send
      Returns:
        current MQTT client instance

    - #### clientId

          String clientId()

      Returns:
        the client identifier

    - #### isConnected

          boolean isConnected()

      Returns:
        if the connection between client and remote server is established/open

Copyright © 2019 Eclipse. All rights reserved.