public interface MqttClient
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
|
Future<MqttConnAckMessage> |
connect(int port,
String host)
Like
connect(int, String, Handler) but returns a Future of the asynchronous result |
MqttClient |
connect(int port,
String host,
Handler<AsyncResult<MqttConnAckMessage>> connectHandler)
Connects to an MQTT server calling connectHandler after connection
|
Future<MqttConnAckMessage> |
connect(int port,
String host,
String serverName)
Like
connect(int, String, String, Handler) but returns a Future of the asynchronous result |
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
|
Future<Void> |
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
|
Future<Integer> |
publish(String topic,
Buffer payload,
MqttQoS qosLevel,
boolean isDup,
boolean isRetain)
Sends the PUBLISH message to the remote MQTT server
|
MqttClient |
publish(String topic,
Buffer payload,
MqttQoS qosLevel,
boolean isDup,
boolean isRetain,
Handler<AsyncResult<Integer>> publishSentHandler)
Sends the PUBLISH message to the remote MQTT server
|
MqttClient |
publishCompletionExpirationHandler(Handler<Integer> publishCompletionExpirationHandler)
Sets a handler which will be called when the client does not receive a PUBACK or
PUBREC/PUBCOMP for a message published using QoS 1 or 2 respectively.
|
MqttClient |
publishCompletionHandler(Handler<Integer> publishCompletionHandler)
Sets a handler which will be called each time the publishing of a message has been completed.
|
MqttClient |
publishCompletionUnknownPacketIdHandler(Handler<Integer> publishCompletionPhantomHandler)
Sets a handler which will be called when the client receives a PUBACK/PUBREC/PUBCOMP with an unknown
packet ID.
|
MqttClient |
publishHandler(Handler<MqttPublishMessage> publishHandler)
Sets handler which will be called each time server publish something to client
|
Future<Integer> |
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
|
Future<Integer> |
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
|
Future<Integer> |
unsubscribe(List<String> topics)
Unsubscribe from receiving messages on given list of topic
|
MqttClient |
unsubscribe(List<String> topics,
Handler<AsyncResult<Integer>> unsubscribeSentHandler)
Unsubscribe from receiving messages on given topics
|
Future<Integer> |
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
|
static MqttClient create(Vertx vertx, MqttClientOptions options)
vertx
- Vert.x instanceoptions
- MQTT client optionsstatic MqttClient create(Vertx vertx)
vertx
- Vert.x instanceMqttClient connect(int port, String host, Handler<AsyncResult<MqttConnAckMessage>> connectHandler)
port
- port of the MQTT serverhost
- hostname/ip address of the MQTT serverconnectHandler
- handler called when the asynchronous connect call endsFuture<MqttConnAckMessage> connect(int port, String host)
connect(int, String, Handler)
but returns a Future
of the asynchronous resultMqttClient connect(int port, String host, String serverName, Handler<AsyncResult<MqttConnAckMessage>> connectHandler)
port
- port of the MQTT serverhost
- hostname/ip address of the MQTT serverserverName
- the SNI server nameconnectHandler
- handler called when the asynchronous connect call endsFuture<MqttConnAckMessage> connect(int port, String host, String serverName)
connect(int, String, String, Handler)
but returns a Future
of the asynchronous resultFuture<Void> disconnect()
Future
of the asynchronous resultMqttClient disconnect(Handler<AsyncResult<Void>> disconnectHandler)
disconnectHandler
- handler called when asynchronous disconnect call endsFuture<Integer> publish(String topic, Buffer payload, MqttQoS qosLevel, boolean isDup, boolean isRetain)
topic
- topic on which the message is publishedpayload
- message payloadqosLevel
- QoS levelisDup
- if the message is a duplicateisRetain
- if the message needs to be retainedFuture
completed after PUBLISH packet sent with packetid (not when QoS 0)MqttClient publish(String topic, Buffer payload, MqttQoS qosLevel, boolean isDup, boolean isRetain, Handler<AsyncResult<Integer>> publishSentHandler)
topic
- topic on which the message is publishedpayload
- message payloadqosLevel
- QoS levelisDup
- if the message is a duplicateisRetain
- if the message needs to be retainedpublishSentHandler
- handler called after PUBLISH packet sent with packetid (not when QoS 0)MqttClient publishCompletionHandler(Handler<Integer> publishCompletionHandler)
For a message that has been published using
publishCompletionHandler
- handler called with the packetIdMqttClient publishCompletionExpirationHandler(Handler<Integer> publishCompletionExpirationHandler)
The time to wait for an acknowledgement message can be configured using
MqttClientOptions.setAckTimeout(int)
.
If the client receives a PUBACK/PUBREC/PUBCOMP for a message after its completion
has expired, the handler registered using publishCompletionUnknownPacketIdHandler(Handler)
will be invoked.
Note that this behavior is outside the scope of the MQTT 3.1.1 specification. The client's default behavior is therefore to wait forever for the server's corresponding acknowledgement.
publishCompletionExpirationHandler
- the handler to call with the ID of the expired packetMqttClient publishCompletionUnknownPacketIdHandler(Handler<Integer> publishCompletionPhantomHandler)
publishCompletionPhantomHandler
- the handler to call with the unknown packet IDMqttClient publishHandler(Handler<MqttPublishMessage> publishHandler)
publishHandler
- handler to callMqttClient subscribeCompletionHandler(Handler<MqttSubAckMessage> subscribeCompletionHandler)
subscribeCompletionHandler
- handler to call. List inside is a granted QoS arrayFuture<Integer> subscribe(String topic, int qos)
topic
- topic you subscribe onqos
- QoS levelFuture
completed after SUBSCRIBE packet sent with packetidMqttClient subscribe(String topic, int qos, Handler<AsyncResult<Integer>> subscribeSentHandler)
topic
- topic you subscribe onqos
- QoS levelsubscribeSentHandler
- handler called after SUBSCRIBE packet sent with packetidFuture<Integer> subscribe(Map<String,Integer> topics)
topics
- topics and related QoS levels to subscribe toFuture
completed after SUBSCRIBE packet sent with packetidMqttClient subscribe(Map<String,Integer> topics, Handler<AsyncResult<Integer>> subscribeSentHandler)
topics
- topics you subscribe onsubscribeSentHandler
- handler called after SUBSCRIBE packet sent with packetidMqttClient unsubscribeCompletionHandler(Handler<Integer> unsubscribeCompletionHandler)
unsubscribeCompletionHandler
- handler to call with the packetidFuture<Integer> unsubscribe(String topic)
topic
- Topic you want to unsubscribe fromFuture
completed after UNSUBSCRIBE packet sent with packetidFuture<Integer> unsubscribe(List<String> topics)
topics
- list of topics you want to unsubscribe fromFuture
completed after UNSUBSCRIBE packet sent with packetidMqttClient unsubscribe(List<String> topics, Handler<AsyncResult<Integer>> unsubscribeSentHandler)
topics
- list of topics you want to unsubscribe fromunsubscribeSentHandler
- handler called after UNSUBSCRIBE packet sentMqttClient unsubscribe(String topic, Handler<AsyncResult<Integer>> unsubscribeSentHandler)
topic
- list of topics you want to unsubscribe fromunsubscribeSentHandler
- handler called after UNSUBSCRIBE packet sentMqttClient pingResponseHandler(Handler<Void> pingResponseHandler)
pingResponseHandler
- handler to callMqttClient exceptionHandler(Handler<Throwable> handler)
io.netty.handler.codec.DecoderException
can be one of the causehandler
- the exception handlerMqttClient closeHandler(Handler<Void> closeHandler)
closeHandler
- handler to callMqttClient ping()
String clientId()
boolean isConnected()
Copyright © 2024 Eclipse. All rights reserved.