Package io.vertx.reactivex.mqtt
Class MqttClient
- java.lang.Object
-
- io.vertx.reactivex.mqtt.MqttClient
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<MqttClient>
__TYPE_ARG
-
Constructor Summary
Constructors Constructor Description MqttClient(MqttClient delegate)
MqttClient(Object delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
clientId()
MqttClient
closeHandler(Handler<Void> closeHandler)
Set a handler that will be called when the connection with server is closedMqttClient
connect(int port, String host)
Connects to an MQTT server calling connectHandler after connectionMqttClient
connect(int port, String host, Handler<AsyncResult<MqttConnAckMessage>> connectHandler)
Connects to an MQTT server calling connectHandler after connectionMqttClient
connect(int port, String host, String serverName)
Connects to an MQTT server calling connectHandler after connectionMqttClient
connect(int port, String host, String serverName, Handler<AsyncResult<MqttConnAckMessage>> connectHandler)
Connects to an MQTT server calling connectHandler after connectionstatic MqttClient
create(Vertx vertx)
Return an MQTT client instance using the default optionsstatic MqttClient
create(Vertx vertx, MqttClientOptions options)
Return an MQTT client instanceMqttClient
disconnect()
Disconnects from the MQTT server calling disconnectHandler after disconnectionMqttClient
disconnect(Handler<AsyncResult<Void>> disconnectHandler)
Disconnects from the MQTT server calling disconnectHandler after disconnectionboolean
equals(Object o)
MqttClient
exceptionHandler(Handler<Throwable> handler)
Set an exception handler for the client, that will be called when an error happens in internal netty structures.MqttClient
getDelegate()
int
hashCode()
boolean
isConnected()
static MqttClient
newInstance(MqttClient arg)
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 sendMqttClient
pingResponseHandler(Handler<Void> pingResponseHandler)
Sets handler which will be called after PINGRESP packet receivingMqttClient
publish(String topic, Buffer payload, io.netty.handler.codec.mqtt.MqttQoS qosLevel, boolean isDup, boolean isRetain)
Sends the PUBLISH message to the remote MQTT serverMqttClient
publish(String topic, Buffer payload, io.netty.handler.codec.mqtt.MqttQoS qosLevel, boolean isDup, boolean isRetain, Handler<AsyncResult<Integer>> publishSentHandler)
Sends the PUBLISH message to the remote MQTT serverMqttClient
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 clientio.reactivex.Single<MqttConnAckMessage>
rxConnect(int port, String host)
Connects to an MQTT server calling connectHandler after connectionio.reactivex.Single<MqttConnAckMessage>
rxConnect(int port, String host, String serverName)
Connects to an MQTT server calling connectHandler after connectionio.reactivex.Completable
rxDisconnect()
Disconnects from the MQTT server calling disconnectHandler after disconnectionio.reactivex.Single<Integer>
rxPublish(String topic, Buffer payload, io.netty.handler.codec.mqtt.MqttQoS qosLevel, boolean isDup, boolean isRetain)
Sends the PUBLISH message to the remote MQTT serverio.reactivex.Single<Integer>
rxSubscribe(String topic, int qos)
Subscribes to the topic with a specified QoS levelio.reactivex.Single<Integer>
rxSubscribe(Map<String,Integer> topics)
Subscribes to the topic and adds a handler which will be called after the request is sentio.reactivex.Single<Integer>
rxUnsubscribe(String topic)
Unsubscribe from receiving messages on given topicio.reactivex.Single<Integer>
rxUnsubscribe(List<String> topics)
Unsubscribe from receiving messages on given topicsMqttClient
subscribe(String topic, int qos)
Subscribes to the topic with a specified QoS levelMqttClient
subscribe(String topic, int qos, Handler<AsyncResult<Integer>> subscribeSentHandler)
Subscribes to the topic with a specified QoS levelMqttClient
subscribe(Map<String,Integer> topics)
Subscribes to the topic and adds a handler which will be called after the request is sentMqttClient
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 sentMqttClient
subscribeCompletionHandler(Handler<MqttSubAckMessage> subscribeCompletionHandler)
Sets handler which will be called after SUBACK packet receivingString
toString()
MqttClient
unsubscribe(String topic)
Unsubscribe from receiving messages on given topicMqttClient
unsubscribe(String topic, Handler<AsyncResult<Integer>> unsubscribeSentHandler)
Unsubscribe from receiving messages on given topicMqttClient
unsubscribe(List<String> topics)
Unsubscribe from receiving messages on given topicsMqttClient
unsubscribe(List<String> topics, Handler<AsyncResult<Integer>> unsubscribeSentHandler)
Unsubscribe from receiving messages on given topicsMqttClient
unsubscribeCompletionHandler(Handler<Integer> unsubscribeCompletionHandler)
Sets handler which will be called after UNSUBACK packet receiving
-
-
-
Field Detail
-
__TYPE_ARG
public static final TypeArg<MqttClient> __TYPE_ARG
-
-
Constructor Detail
-
MqttClient
public MqttClient(MqttClient delegate)
-
MqttClient
public MqttClient(Object delegate)
-
-
Method Detail
-
getDelegate
public MqttClient getDelegate()
-
create
public static MqttClient create(Vertx vertx, MqttClientOptions options)
Return an MQTT client instance- Parameters:
vertx
- Vert.x instanceoptions
- MQTT client options- Returns:
- MQTT client instance
-
create
public static MqttClient create(Vertx vertx)
Return an MQTT client instance using the default options- Parameters:
vertx
- Vert.x instance- Returns:
- MQTT client instance
-
connect
public MqttClient connect(int port, String host, Handler<AsyncResult<MqttConnAckMessage>> connectHandler)
Connects to an MQTT server calling connectHandler after connection- Parameters:
port
- port of the MQTT serverhost
- hostname/ip address of the MQTT serverconnectHandler
- handler called when the asynchronous connect call ends- Returns:
- current MQTT client instance
-
connect
public MqttClient connect(int port, String host)
Connects to an MQTT server calling connectHandler after connection- Parameters:
port
- port of the MQTT serverhost
- hostname/ip address of the MQTT server- Returns:
- current MQTT client instance
-
rxConnect
public io.reactivex.Single<MqttConnAckMessage> rxConnect(int port, String host)
Connects to an MQTT server calling connectHandler after connection- Parameters:
port
- port of the MQTT serverhost
- hostname/ip address of the MQTT server- Returns:
- current MQTT client instance
-
connect
public MqttClient connect(int port, String host, String serverName, Handler<AsyncResult<MqttConnAckMessage>> connectHandler)
Connects to an MQTT server calling connectHandler after connection- Parameters:
port
- port of the MQTT serverhost
- hostname/ip address of the MQTT serverserverName
- the SNI server nameconnectHandler
- handler called when the asynchronous connect call ends- Returns:
- current MQTT client instance
-
connect
public MqttClient connect(int port, String host, String serverName)
Connects to an MQTT server calling connectHandler after connection- Parameters:
port
- port of the MQTT serverhost
- hostname/ip address of the MQTT serverserverName
- the SNI server name- Returns:
- current MQTT client instance
-
rxConnect
public io.reactivex.Single<MqttConnAckMessage> rxConnect(int port, String host, String serverName)
Connects to an MQTT server calling connectHandler after connection- Parameters:
port
- port of the MQTT serverhost
- hostname/ip address of the MQTT serverserverName
- the SNI server name- Returns:
- current MQTT client instance
-
disconnect
public MqttClient disconnect(Handler<AsyncResult<Void>> disconnectHandler)
Disconnects from the MQTT server calling disconnectHandler after disconnection- Parameters:
disconnectHandler
- handler called when asynchronous disconnect call ends- Returns:
- current MQTT client instance
-
disconnect
public MqttClient disconnect()
Disconnects from the MQTT server calling disconnectHandler after disconnection- Returns:
- current MQTT client instance
-
rxDisconnect
public io.reactivex.Completable rxDisconnect()
Disconnects from the MQTT server calling disconnectHandler after disconnection- Returns:
- current MQTT client instance
-
publish
public MqttClient publish(String topic, Buffer payload, io.netty.handler.codec.mqtt.MqttQoS qosLevel, boolean isDup, boolean isRetain, Handler<AsyncResult<Integer>> publishSentHandler)
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 retainedpublishSentHandler
- handler called after PUBLISH packet sent with packetid (not when QoS 0)- Returns:
- current MQTT client instance
-
publish
public MqttClient 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- 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:
- current MQTT client instance
-
rxPublish
public io.reactivex.Single<Integer> rxPublish(String topic, 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:
- current MQTT client instance
-
publishCompletionHandler
public MqttClient publishCompletionHandler(Handler<Integer> publishCompletionHandler)
Sets a handler which will be called each time the publishing of a message has been completed.For a message that has been published using
- QoS 0 this means that the client has successfully sent the corresponding PUBLISH packet,
- QoS 1 this means that a corresponding PUBACK has been received from the server,
- QoS 2 this means that a corresponding PUBCOMP has been received from the server.
- Parameters:
publishCompletionHandler
- handler called with the packetId- Returns:
- current MQTT client instance
-
publishCompletionExpirationHandler
public 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.The time to wait for an acknowledgement message can be configured using
MqttClientOptions
. If the client receives a PUBACK/PUBREC/PUBCOMP for a message after its completion has expired, the handler registered usingpublishCompletionUnknownPacketIdHandler(io.vertx.core.Handler<java.lang.Integer>)
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.
- Parameters:
publishCompletionExpirationHandler
- the handler to call with the ID of the expired packet- Returns:
- current MQTT client instance
-
publishCompletionUnknownPacketIdHandler
public 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.- Parameters:
publishCompletionPhantomHandler
- the handler to call with the unknown packet ID- Returns:
- current MQTT client instance
-
publishHandler
public MqttClient publishHandler(Handler<MqttPublishMessage> publishHandler)
Sets handler which will be called each time server publish something to client- Parameters:
publishHandler
- handler to call- Returns:
- current MQTT client instance
-
subscribeCompletionHandler
public MqttClient subscribeCompletionHandler(Handler<MqttSubAckMessage> subscribeCompletionHandler)
Sets handler which will be called after SUBACK packet receiving- Parameters:
subscribeCompletionHandler
- handler to call. List inside is a granted QoS array- Returns:
- current MQTT client instance
-
subscribe
public MqttClient subscribe(String topic, int qos, Handler<AsyncResult<Integer>> subscribeSentHandler)
Subscribes to the topic with a specified QoS level- Parameters:
topic
- topic you subscribe onqos
- QoS levelsubscribeSentHandler
- handler called after SUBSCRIBE packet sent with packetid- Returns:
- current MQTT client instance
-
subscribe
public MqttClient subscribe(String topic, int qos)
Subscribes to the topic with a specified QoS level- Parameters:
topic
- topic you subscribe onqos
- QoS level- Returns:
- current MQTT client instance
-
rxSubscribe
public io.reactivex.Single<Integer> rxSubscribe(String topic, int qos)
Subscribes to the topic with a specified QoS level- Parameters:
topic
- topic you subscribe onqos
- QoS level- Returns:
- current MQTT client instance
-
subscribe
public 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- Parameters:
topics
- topics you subscribe onsubscribeSentHandler
- handler called after SUBSCRIBE packet sent with packetid- Returns:
- current MQTT client instance
-
subscribe
public MqttClient subscribe(Map<String,Integer> topics)
Subscribes to the topic and adds a handler which will be called after the request is sent- Parameters:
topics
- topics you subscribe on- Returns:
- current MQTT client instance
-
rxSubscribe
public io.reactivex.Single<Integer> rxSubscribe(Map<String,Integer> topics)
Subscribes to the topic and adds a handler which will be called after the request is sent- Parameters:
topics
- topics you subscribe on- Returns:
- current MQTT client instance
-
unsubscribeCompletionHandler
public MqttClient unsubscribeCompletionHandler(Handler<Integer> unsubscribeCompletionHandler)
Sets handler which will be called after UNSUBACK packet receiving- Parameters:
unsubscribeCompletionHandler
- handler to call with the packetid- Returns:
- current MQTT client instance
-
unsubscribe
public MqttClient unsubscribe(List<String> topics, Handler<AsyncResult<Integer>> unsubscribeSentHandler)
Unsubscribe from receiving messages on given topics- Parameters:
topics
- list of topics you want to unsubscribe fromunsubscribeSentHandler
- handler called after UNSUBSCRIBE packet sent- Returns:
- current MQTT client instance
-
unsubscribe
public MqttClient unsubscribe(List<String> topics)
Unsubscribe from receiving messages on given topics- Parameters:
topics
- list of topics you want to unsubscribe from- Returns:
- current MQTT client instance
-
rxUnsubscribe
public io.reactivex.Single<Integer> rxUnsubscribe(List<String> topics)
Unsubscribe from receiving messages on given topics- Parameters:
topics
- list of topics you want to unsubscribe from- Returns:
- current MQTT client instance
-
unsubscribe
public MqttClient unsubscribe(String topic, Handler<AsyncResult<Integer>> unsubscribeSentHandler)
Unsubscribe from receiving messages on given topic- Parameters:
topic
- list of topics you want to unsubscribe fromunsubscribeSentHandler
- handler called after UNSUBSCRIBE packet sent- Returns:
- current MQTT client instance
-
unsubscribe
public MqttClient unsubscribe(String topic)
Unsubscribe from receiving messages on given topic- Parameters:
topic
- list of topics you want to unsubscribe from- Returns:
- current MQTT client instance
-
rxUnsubscribe
public io.reactivex.Single<Integer> rxUnsubscribe(String topic)
Unsubscribe from receiving messages on given topic- Parameters:
topic
- list of topics you want to unsubscribe from- Returns:
- current MQTT client instance
-
pingResponseHandler
public MqttClient pingResponseHandler(Handler<Void> pingResponseHandler)
Sets handler which will be called after PINGRESP packet receiving- Parameters:
pingResponseHandler
- handler to call- Returns:
- current MQTT client instance
-
exceptionHandler
public MqttClient exceptionHandler(Handler<Throwable> handler)
Set an exception handler for the client, that will be called when an error happens in internal netty structures.io.netty.handler.codec.DecoderException
can be one of the cause- Parameters:
handler
- the exception handler- Returns:
- current MQTT client instance
-
closeHandler
public MqttClient closeHandler(Handler<Void> closeHandler)
Set a handler that will be called when the connection with server is closed- Parameters:
closeHandler
- handler to call- Returns:
- current MQTT client instance
-
ping
public 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- 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(MqttClient arg)
-
-