Class MqttClient


  • public class MqttClient
    extends Object
    An MQTT client

    NOTE: This class has been automatically generated from the original non Mutiny-ified interface using Vert.x codegen.

    • Constructor Detail

      • MqttClient

        public MqttClient​(io.vertx.mqtt.MqttClient delegate)
      • MqttClient

        public MqttClient​(Object delegate)
    • Method Detail

      • getDelegate

        public io.vertx.mqtt.MqttClient getDelegate()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • create

        public static MqttClient create​(Vertx vertx,
                                        io.vertx.mqtt.MqttClientOptions options)
        Parameters:
        vertx - Vert.x instance
        options - MQTT client options
        Returns:
        MQTT client instance
      • create

        public static MqttClient create​(Vertx vertx)
        Parameters:
        vertx - Vert.x instance
        Returns:
        MQTT client instance
      • connect

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<MqttConnAckMessage> connect​(int port,
                                                                  String host)
        Connects to an MQTT server calling connectHandler after connection

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        port - port of the MQTT server
        host - hostname/ip address of the MQTT server
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • connectAndAwait

        public MqttConnAckMessage connectAndAwait​(int port,
                                                  String host)
        Blocking variant of connect(int,String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        port - port of the MQTT server
        host - hostname/ip address of the MQTT server
        Returns:
        the MqttConnAckMessage instance produced by the operation.
      • connectAndForget

        public MqttClient connectAndForget​(int port,
                                           String host)
        Variant of connect(int,String) that ignores the result of the operation.

        This method subscribes on the result of connect(int,String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from connect(int,String) but you don't need to compose it with other operations.

        Parameters:
        port - port of the MQTT server
        host - hostname/ip address of the MQTT server
        Returns:
        the instance of MqttClient to chain method calls.
      • connect

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<MqttConnAckMessage> connect​(int port,
                                                                  String host,
                                                                  String serverName)
        Connects to an MQTT server calling connectHandler after connection

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        port - port of the MQTT server
        host - hostname/ip address of the MQTT server
        serverName - the SNI server name
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • connectAndAwait

        public MqttConnAckMessage connectAndAwait​(int port,
                                                  String host,
                                                  String serverName)
        Blocking variant of connect(int,String,String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        port - port of the MQTT server
        host - hostname/ip address of the MQTT server
        serverName - the SNI server name
        Returns:
        the MqttConnAckMessage instance produced by the operation.
      • connectAndForget

        public MqttClient connectAndForget​(int port,
                                           String host,
                                           String serverName)
        Variant of connect(int,String,String) that ignores the result of the operation.

        This method subscribes on the result of connect(int,String,String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from connect(int,String,String) but you don't need to compose it with other operations.

        Parameters:
        port - port of the MQTT server
        host - hostname/ip address of the MQTT server
        serverName - the SNI server name
        Returns:
        the instance of MqttClient to chain method calls.
      • disconnect

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<Void> disconnect()
        Disconnects from the MQTT server calling disconnectHandler after disconnection

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • disconnectAndAwait

        public Void disconnectAndAwait()
        Blocking variant of disconnect().

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Returns:
        the Void instance produced by the operation.
      • disconnectAndForget

        public MqttClient disconnectAndForget()
        Variant of disconnect() that ignores the result of the operation.

        This method subscribes on the result of disconnect(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from disconnect() but you don't need to compose it with other operations.

        Returns:
        the instance of MqttClient to chain method calls.
      • publish

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<Integer> 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

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        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:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • publishAndAwait

        public Integer publishAndAwait​(String topic,
                                       Buffer payload,
                                       io.netty.handler.codec.mqtt.MqttQoS qosLevel,
                                       boolean isDup,
                                       boolean isRetain)
        Blocking variant of publish(String,io.vertx.mutiny.core.buffer.Buffer,MqttQoS,boolean,boolean).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        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:
        the Integer instance produced by the operation.
      • publishCompletionHandler

        public MqttClient publishCompletionHandler​(Consumer<Integer> publishCompletionHandler)
        Parameters:
        publishCompletionHandler - handler called with the packetId
        Returns:
      • publishCompletionExpirationHandler

        public MqttClient publishCompletionExpirationHandler​(Consumer<Integer> publishCompletionExpirationHandler)
        Parameters:
        publishCompletionExpirationHandler - the handler to call with the ID of the expired packet
        Returns:
      • publishCompletionUnknownPacketIdHandler

        public MqttClient publishCompletionUnknownPacketIdHandler​(Consumer<Integer> publishCompletionPhantomHandler)
        Parameters:
        publishCompletionPhantomHandler - the handler to call with the unknown packet ID
        Returns:
      • subscribeCompletionHandler

        public MqttClient subscribeCompletionHandler​(Consumer<MqttSubAckMessage> subscribeCompletionHandler)
        Parameters:
        subscribeCompletionHandler - handler to call. List inside is a granted QoS array
        Returns:
      • subscribe

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<Integer> subscribe​(String topic,
                                                         int qos)
        Subscribes to the topic with a specified QoS level

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        topic - topic you subscribe on
        qos - QoS level
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • subscribeAndAwait

        public Integer subscribeAndAwait​(String topic,
                                         int qos)
        Blocking variant of subscribe(String,int).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        topic - topic you subscribe on
        qos - QoS level
        Returns:
        the Integer instance produced by the operation.
      • subscribeAndForget

        public MqttClient subscribeAndForget​(String topic,
                                             int qos)
        Variant of subscribe(String,int) that ignores the result of the operation.

        This method subscribes on the result of subscribe(String,int), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from subscribe(String,int) but you don't need to compose it with other operations.

        Parameters:
        topic - topic you subscribe on
        qos - QoS level
        Returns:
        the instance of MqttClient to chain method calls.
      • subscribe

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<Integer> subscribe​(Map<String,​Integer> topics)
        Subscribes to the topic and adds a handler which will be called after the request is sent

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        topics - topics you subscribe on
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • subscribeAndAwait

        public Integer subscribeAndAwait​(Map<String,​Integer> topics)
        Blocking variant of subscribe(Map).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        topics - topics you subscribe on
        Returns:
        the Integer instance produced by the operation.
      • subscribeAndForget

        public MqttClient subscribeAndForget​(Map<String,​Integer> topics)
        Variant of subscribe(Map) that ignores the result of the operation.

        This method subscribes on the result of subscribe(Map), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from subscribe(Map) but you don't need to compose it with other operations.

        Parameters:
        topics - topics you subscribe on
        Returns:
        the instance of MqttClient to chain method calls.
      • unsubscribeCompletionHandler

        public MqttClient unsubscribeCompletionHandler​(Consumer<Integer> unsubscribeCompletionHandler)
        Parameters:
        unsubscribeCompletionHandler - handler to call with the packetid
        Returns:
      • unsubscribe

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<Integer> unsubscribe​(List<String> topics)
        Unsubscribe from receiving messages on given topics

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        topics - list of topics you want to unsubscribe from
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • unsubscribeAndAwait

        public Integer unsubscribeAndAwait​(List<String> topics)
        Blocking variant of unsubscribe(List).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        topics - list of topics you want to unsubscribe from
        Returns:
        the Integer instance produced by the operation.
      • unsubscribeAndForget

        public MqttClient unsubscribeAndForget​(List<String> topics)
        Variant of unsubscribe(List) that ignores the result of the operation.

        This method subscribes on the result of unsubscribe(List), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from unsubscribe(List) but you don't need to compose it with other operations.

        Parameters:
        topics - list of topics you want to unsubscribe from
        Returns:
        the instance of MqttClient to chain method calls.
      • unsubscribe

        @CheckReturnValue
        public io.smallrye.mutiny.Uni<Integer> unsubscribe​(String topic)
        Unsubscribe from receiving messages on given topic

        Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

        Parameters:
        topic - list of topics you want to unsubscribe from
        Returns:
        the uni firing the result of the operation when completed, or a failure if the operation failed.
      • unsubscribeAndAwait

        public Integer unsubscribeAndAwait​(String topic)
        Blocking variant of unsubscribe(String).

        This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

        Parameters:
        topic - list of topics you want to unsubscribe from
        Returns:
        the Integer instance produced by the operation.
      • unsubscribeAndForget

        public MqttClient unsubscribeAndForget​(String topic)
        Variant of unsubscribe(String) that ignores the result of the operation.

        This method subscribes on the result of unsubscribe(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from unsubscribe(String) but you don't need to compose it with other operations.

        Parameters:
        topic - list of topics you want to unsubscribe from
        Returns:
        the instance of MqttClient to chain method calls.
      • pingResponseHandler

        public MqttClient pingResponseHandler​(Runnable pingResponseHandler)
        Parameters:
        pingResponseHandler - handler to call
        Returns:
      • exceptionHandler

        public MqttClient exceptionHandler​(Consumer<Throwable> handler)
        Parameters:
        handler - the exception handler
        Returns:
      • closeHandler

        public MqttClient closeHandler​(Runnable closeHandler)
        Parameters:
        closeHandler - handler to call
        Returns:
      • ping

        public MqttClient ping()
        Returns:
        current MQTT client instance
      • clientId

        public String clientId()
        Returns:
        the client identifier
      • isConnected

        public boolean isConnected()
        Returns:
        if the connection between client and remote server is established/open
      • newInstance

        public static MqttClient newInstance​(io.vertx.mqtt.MqttClient arg)