Interface MqttClientSession

  • All Known Implementing Classes:
    MqttClientSessionImpl

    public interface MqttClientSession
    An MQTT client session.
    • Method Detail

      • create

        static MqttClientSession create​(io.vertx.core.Vertx vertx,
                                        MqttClientSessionOptions options)
        Create a new MQTT client session.

        The session will initially be disconnected, and must be started using start().

        Parameters:
        vertx - Vert.x instance
        options - MQTT client session options
        Returns:
        MQTT client session instance
      • sessionStateHandler

        MqttClientSession sessionStateHandler​(io.vertx.core.Handler<SessionEvent> sessionStateHandler)
        Set the session state handler.
        Parameters:
        sessionStateHandler - The new handler, will overwrite the old one.
        Returns:
        current MQTT client session instance
      • subscriptionStateHandler

        MqttClientSession subscriptionStateHandler​(io.vertx.core.Handler<SubscriptionEvent> subscriptionStateHandler)
        Set the subscription state handler.
        Parameters:
        subscriptionStateHandler - The new handler, will overwrite the old one.
        Returns:
        current MQTT client session instance
      • publishCompletionHandler

        MqttClientSession publishCompletionHandler​(io.vertx.core.Handler<Integer> publishCompleteHandler)
        Set the publish complete handler.
        Parameters:
        publishCompleteHandler - The new handler, will overwrite the old one.
        Returns:
        current MQTT client session instance
        See Also:
        MqttClient.publishCompletionHandler(Handler)
      • publishCompletionExpirationHandler

        MqttClientSession publishCompletionExpirationHandler​(io.vertx.core.Handler<Integer> publishCompletionExpirationHandler)
        Set the publish completion expiration handler.
        Parameters:
        publishCompletionExpirationHandler - The new handler, will overwrite the old one.
        Returns:
        current MQTT client session instance
        See Also:
        MqttClient.publishCompletionExpirationHandler(Handler)
      • publishCompletionUnknownPacketIdHandler

        MqttClientSession publishCompletionUnknownPacketIdHandler​(io.vertx.core.Handler<Integer> publishCompletionUnknownPacketIdHandler)
        Set the publish completion unknown packet id handler.
        Parameters:
        publishCompletionUnknownPacketIdHandler - The new handler, will overwrite the old one.
        Returns:
        current MQTT client session instance
        See Also:
        MqttClient.publishCompletionUnknownPacketIdHandler(Handler)
      • getState

        SessionState getState()
        Get the current session state.
        Returns:
        The current state.
      • getSubscriptionState

        SubscriptionState getSubscriptionState​(String topicFilter)
        Get a current subscription state.
        Parameters:
        topicFilter - The topic filter to get the state for.
        Returns:
        The current state of the requested subscription.
      • isConnected

        default boolean isConnected()
        Check if the session is currently connected.
        Returns:
        true if the session is currently connected, false otherwise.
      • subscribe

        io.vertx.core.Future<Integer> subscribe​(String topic,
                                                RequestedQoS qos)
        Subscribes to a single topic with related QoS level.
        Parameters:
        topic - The topic to subscribe to.
        qos - The QoS to request from the server.
        Returns:
        current MQTT client session instance
      • unsubscribe

        io.vertx.core.Future<Void> unsubscribe​(String topic)
        Unsubscribe from receiving messages on given topic
        Parameters:
        topic - Topic you want to unsubscribe from
        Returns:
        current MQTT client session instance
      • messageHandler

        MqttClientSession messageHandler​(io.vertx.core.Handler<io.vertx.mqtt.messages.MqttPublishMessage> messageHandler)
        Sets handler which will be called each time server publish something to client
        Parameters:
        messageHandler - handler to call
        Returns:
        current MQTT client session instance
      • exceptionHandler

        MqttClientSession exceptionHandler​(io.vertx.core.Handler<Throwable> exceptionHandler)
        Sets handler which will be called in case of an exception
        Parameters:
        exceptionHandler - handler to call
        Returns:
        current MQTT client session instance
      • publish

        io.vertx.core.Future<Integer> publish​(String topic,
                                              io.vertx.core.buffer.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:
        a Future completed after PUBLISH packet sent with packetid (not when QoS 0)
      • publish

        default io.vertx.core.Future<Integer> publish​(String topic,
                                                      io.vertx.core.buffer.Buffer payload,
                                                      io.netty.handler.codec.mqtt.MqttQoS qosLevel)
        Sends the PUBLISH message to the remote MQTT server
        Parameters:
        topic - topic on which the message is published
        payload - message payload
        qosLevel - QoS level
        Returns:
        a Future completed after PUBLISH packet sent with packetid (not when QoS 0)