Class MqttClient
java.lang.Object
io.vertx.reactivex.mqtt.MqttClient
- All Implemented Interfaces:
io.vertx.lang.rx.RxDelegate
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionIt is used for Enhanced Authentication and is able to carry an authentication method and authentication data.authenticationExchangeHandler(Handler<MqttAuthenticationExchangeMessage> authenticationExchangeHandler) Sets handler which will be called after AUTH packet receivingclientId()closeHandler(Handler<Void> closeHandler) Set a handler that will be called when the connection with server is closedConnects to an MQTT server calling connectHandler after connectionConnects to an MQTT server calling connectHandler after connectionstatic MqttClientReturn an MQTT client instance using the default optionsstatic MqttClientcreate(Vertx vertx, MqttClientOptions options) Return an MQTT client instanceDisconnects from the MQTT serverbooleanexceptionHandler(Handler<Throwable> handler) Set an exception handler for the client, that will be called when an error happens in internal netty structures.inthashCode()booleanstatic MqttClientnewInstance(MqttClient arg) voidpause()Pause the reading channel, so no new byte are read from the server.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 sendpingResponseHandler(Handler<Void> pingResponseHandler) Sets handler which will be called after PINGRESP packet receivingSends the PUBLISH message to the remote MQTT serverSends the PUBLISH message to the remote MQTT serverpublishCompletionExpirationHandler(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.publishCompletionHandler(Handler<Integer> publishCompletionHandler) Sets a handler which will be called each time the publishing of a message has been completed.publishCompletionUnknownPacketIdHandler(Handler<Integer> publishCompletionPhantomHandler) Sets a handler which will be called when the client receives a PUBACK/PUBREC/PUBCOMP with an unknown packet ID.publishHandler(Handler<MqttPublishMessage> publishHandler) Sets handler which will be called each time server publish something to clientpublishRelease(int publishMessageId) Sends the PUBREL message to the remote MQTT server.voidresume()Resume the reading channel. seepause()Available after connection is established.It is used for Enhanced Authentication and is able to carry an authentication method and authentication data.Connects to an MQTT server calling connectHandler after connectionConnects to an MQTT server calling connectHandler after connectionDisconnects from the MQTT serverSends the PUBLISH message to the remote MQTT serverSends the PUBLISH message to the remote MQTT serverrxPublishRelease(int publishMessageId) Sends the PUBREL message to the remote MQTT server.rxSubscribe(String topic, int qos) Subscribes to the topic with a specified QoS levelrxSubscribe(Map<String, Integer> topics) Subscribes to the topics with related QoS levelsrxUnsubscribe(String topic) Unsubscribe from receiving messages on given topicrxUnsubscribe(List<String> topics) Unsubscribe from receiving messages on given list of topicSubscribes to the topic with a specified QoS levelSubscribes to the topics with related QoS levelssubscribeCompletionHandler(Handler<MqttSubAckMessage> subscribeCompletionHandler) Sets handler which will be called after SUBACK packet receivingtoString()unsubscribe(String topic) Unsubscribe from receiving messages on given topicunsubscribe(List<String> topics) Unsubscribe from receiving messages on given list of topicunsubscribeCompletionHandler(Handler<Integer> unsubscribeCompletionHandler) Sets handler which will be called after UNSUBACK packet receiving
-
Field Details
-
__TYPE_ARG
-
-
Constructor Details
-
MqttClient
-
MqttClient
-
-
Method Details
-
toString
-
equals
-
hashCode
-
getDelegate
- Specified by:
getDelegatein interfaceio.vertx.lang.rx.RxDelegate
-
create
Return an MQTT client instance- Parameters:
vertx- Vert.x instanceoptions- MQTT client options- Returns:
- MQTT client instance
-
create
Return an MQTT client instance using the default options- Parameters:
vertx- Vert.x instance- Returns:
- MQTT client instance
-
connect
Connects to an MQTT server calling connectHandler after connection- Parameters:
port- port of the MQTT serverhost- hostname/ip address of the MQTT server- Returns:
- a future notified when the connect call ends
-
rxConnect
Connects to an MQTT server calling connectHandler after connection- Parameters:
port- port of the MQTT serverhost- hostname/ip address of the MQTT server- Returns:
- a future notified when the connect call ends
-
connect
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:
- a future notified when the connect call ends
-
rxConnect
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:
- a future notified when the connect call ends
-
disconnect
-
rxDisconnect
Disconnects from the MQTT server- Returns:
- a
Futureof the asynchronous result
-
publish
public Future<Integer> publish(String topic, Buffer payload, 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)
-
rxPublish
public Single<Integer> rxPublish(String topic, Buffer payload, 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
public Future<Integer> publish(int id, String topic, Buffer payload, MqttQoS qosLevel, boolean isDup, boolean isRetain) Sends the PUBLISH message to the remote MQTT server- Parameters:
id- the message IDtopic- 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)
-
rxPublish
public Single<Integer> rxPublish(int id, String topic, Buffer payload, MqttQoS qosLevel, boolean isDup, boolean isRetain) Sends the PUBLISH message to the remote MQTT server- Parameters:
id- the message IDtopic- 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)
-
publishRelease
-
rxPublishRelease
Sends the PUBREL message to the remote MQTT server. This can be used when a PUBREL message expires- Parameters:
publishMessageId- identifier of the PUBLISH message to acknowledge- Returns:
- a reference to this, so the API can be used fluently
-
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(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.
- 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
Sets handler which will be called each time server publish something to client- Parameters:
publishHandler- handler to call- Returns:
- current MQTT client instance
-
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
-
rxSubscribe
-
subscribe
-
rxSubscribe
-
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
-
rxUnsubscribe
-
unsubscribe
-
rxUnsubscribe
-
authenticationExchangeHandler
public MqttClient authenticationExchangeHandler(Handler<MqttAuthenticationExchangeMessage> authenticationExchangeHandler) Sets handler which will be called after AUTH packet receiving- Parameters:
authenticationExchangeHandler- handler to call- Returns:
- current MQTT client instance
-
authenticationExchange
It is used for Enhanced Authentication and is able to carry an authentication method and authentication data.- Parameters:
message- authentication exchange message- Returns:
- a
Futurecompleted after AUTH packet sent
-
rxAuthenticationExchange
It is used for Enhanced Authentication and is able to carry an authentication method and authentication data.- Parameters:
message- authentication exchange message- Returns:
- a
Futurecompleted after AUTH packet sent
-
pingResponseHandler
Sets handler which will be called after PINGRESP packet receiving- Parameters:
pingResponseHandler- handler to call- Returns:
- current MQTT client instance
-
exceptionHandler
Set an exception handler for the client, that will be called when an error happens in internal netty structures.io.netty.handler.codec.DecoderExceptioncan be one of the cause- Parameters:
handler- the exception handler- Returns:
- current MQTT client instance
-
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
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
-
pause
public void pause()Pause the reading channel, so no new byte are read from the server. Available after connection is established.This simply delegates to
NetSocket.pause(). -
resume
public void resume()Resume the reading channel. seepause()Available after connection is established.This simply delegates to
NetSocket.resume(). -
clientId
- Returns:
- the client identifier
-
isConnected
public boolean isConnected()- Returns:
- if the connection between client and remote server is established/open
-
newInstance
-