Interface MqttClientSession
- All Known Implementing Classes:
MqttClientSessionImpl
public interface MqttClientSession
An MQTT client session.
-
Method Summary
Modifier and TypeMethodDescriptionstatic MqttClientSessioncreate(io.vertx.core.Vertx vertx, MqttClientSessionOptions options) Create a new MQTT client session.exceptionHandler(io.vertx.core.Handler<Throwable> exceptionHandler) Sets handler which will be called in case of an exceptiongetState()Get the current session state.getSubscriptionState(String topicFilter) Get a current subscription state.default booleanCheck if the session is currently connected.messageHandler(io.vertx.core.Handler<io.vertx.mqtt.messages.MqttPublishMessage> messageHandler) Sets handler which will be called each time server publish something to clientdefault 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 serverio.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 serverpublishCompletionExpirationHandler(io.vertx.core.Handler<Integer> publishCompletionExpirationHandler) Set the publish completion expiration handler.publishCompletionHandler(io.vertx.core.Handler<Integer> publishCompleteHandler) Set the publish complete handler.publishCompletionUnknownPacketIdHandler(io.vertx.core.Handler<Integer> publishCompletionUnknownPacketIdHandler) Set the publish completion unknown packet id handler.sessionStateHandler(io.vertx.core.Handler<SessionEvent> sessionStateHandler) Set the session state handler.io.vertx.core.Future<Void>start()Start the session.io.vertx.core.Future<Void>stop()Stop the session.io.vertx.core.Future<Integer>subscribe(String topic, RequestedQoS qos) Subscribes to a single topic with related QoS level.subscriptionStateHandler(io.vertx.core.Handler<SubscriptionEvent> subscriptionStateHandler) Set the subscription state handler.io.vertx.core.Future<Void>unsubscribe(String topic) Unsubscribe from receiving messages on given topic
-
Method Details
-
create
Create a new MQTT client session.The session will initially be disconnected, and must be started using
start().- Parameters:
vertx- Vert.x instanceoptions- MQTT client session options- Returns:
- MQTT client session instance
-
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
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)
-
start
io.vertx.core.Future<Void> start()Start the session. This will try to drive the connection toSessionState.CONNECTED. -
stop
io.vertx.core.Future<Void> stop()Stop the session. This will try to drive the connection toSessionState.DISCONNECTED. -
getState
SessionState getState()Get the current session state.- Returns:
- The current state.
-
getSubscriptionState
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:
trueif the session is currently connected,falseotherwise.
-
subscribe
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
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
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 publishedpayload- message payloadqosLevel- QoS levelisDup- if the message is a duplicateisRetain- if the message needs to be retained- Returns:
- a
Futurecompleted 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 publishedpayload- message payloadqosLevel- QoS level- Returns:
- a
Futurecompleted after PUBLISH packet sent with packetid (not when QoS 0)
-