Interface MqttClientSession
-
- All Known Implementing Classes:
MqttClientSessionImpl
public interface MqttClientSession
An MQTT client session.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static MqttClientSession
create(io.vertx.core.Vertx vertx, MqttClientSessionOptions options)
Create a new MQTT client session.MqttClientSession
exceptionHandler(io.vertx.core.Handler<Throwable> exceptionHandler)
Sets handler which will be called in case of an exceptionSessionState
getState()
Get the current session state.SubscriptionState
getSubscriptionState(String topicFilter)
Get a current subscription state.default boolean
isConnected()
Check if the session is currently connected.MqttClientSession
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 serverMqttClientSession
publishCompletionExpirationHandler(io.vertx.core.Handler<Integer> publishCompletionExpirationHandler)
Set the publish completion expiration handler.MqttClientSession
publishCompletionHandler(io.vertx.core.Handler<Integer> publishCompleteHandler)
Set the publish complete handler.MqttClientSession
publishCompletionUnknownPacketIdHandler(io.vertx.core.Handler<Integer> publishCompletionUnknownPacketIdHandler)
Set the publish completion unknown packet id handler.MqttClientSession
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.MqttClientSession
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 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 instanceoptions
- 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)
-
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
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 publishedpayload
- message payloadqosLevel
- QoS levelisDup
- if the message is a duplicateisRetain
- 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 publishedpayload
- message payloadqosLevel
- QoS level- Returns:
- a
Future
completed after PUBLISH packet sent with packetid (not when QoS 0)
-
-