Class: MqttClient

vertx-mqtt-js/mqtt_client~ MqttClient

new MqttClient()

An MQTT client
Source:

Methods

clientId() → {string}

Source:
Returns:
the client identifier
Type
string

closeHandler(closeHandler) → {MqttClient}

Set a handler that will be called when the connection with server is closed
Parameters:
Name Type Description
closeHandler function handler to call
Source:
Returns:
current MQTT client instance
Type
MqttClient

connect(port, host, serverName, connectHandler) → {MqttClient}

Connects to an MQTT server calling connectHandler after connection
Parameters:
Name Type Description
port number port of the MQTT server
host string hostname/ip address of the MQTT server
serverName string the SNI server name
connectHandler function handler called when the asynchronous connect call ends
Source:
Returns:
current MQTT client instance
Type
MqttClient

disconnect(disconnectHandler) → {MqttClient}

Disconnects from the MQTT server calling disconnectHandler after disconnection
Parameters:
Name Type Description
disconnectHandler function handler called when asynchronous disconnect call ends
Source:
Returns:
current MQTT client instance
Type
MqttClient

exceptionHandler(handler) → {MqttClient}

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:
Name Type Description
handler function the exception handler
Source:
Returns:
current MQTT client instance
Type
MqttClient

isConnected() → {boolean}

Source:
Returns:
if the connection between client and remote server is established/open
Type
boolean

ping() → {MqttClient}

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
Source:
Returns:
current MQTT client instance
Type
MqttClient

pingResponseHandler(pingResponseHandler) → {MqttClient}

Sets handler which will be called after PINGRESP packet receiving
Parameters:
Name Type Description
pingResponseHandler function handler to call
Source:
Returns:
current MQTT client instance
Type
MqttClient

publish(topic, payload, qosLevel, isDup, isRetain, publishSentHandler) → {MqttClient}

Sends the PUBLISH message to the remote MQTT server
Parameters:
Name Type Description
topic string topic on which the message is published
payload Buffer message payload
qosLevel Object QoS level
isDup boolean if the message is a duplicate
isRetain boolean if the message needs to be retained
publishSentHandler function handler called after PUBLISH packet sent with packetid (not when QoS 0)
Source:
Returns:
current MQTT client instance
Type
MqttClient

publishCompletionHandler(publishCompletionHandler) → {MqttClient}

Sets handler which will be called each time publish is completed
Parameters:
Name Type Description
publishCompletionHandler function handler called with the packetId
Source:
Returns:
current MQTT client instance
Type
MqttClient

publishHandler(publishHandler) → {MqttClient}

Sets handler which will be called each time server publish something to client
Parameters:
Name Type Description
publishHandler function handler to call
Source:
Returns:
current MQTT client instance
Type
MqttClient

subscribe(topic, qos, subscribeSentHandler) → {MqttClient}

Subscribes to the topic with a specified QoS level
Parameters:
Name Type Description
topic string topic you subscribe on
qos number QoS level
subscribeSentHandler function handler called after SUBSCRIBE packet sent with packetid
Source:
Returns:
current MQTT client instance
Type
MqttClient

subscribeCompletionHandler(subscribeCompletionHandler) → {MqttClient}

Sets handler which will be called after SUBACK packet receiving
Parameters:
Name Type Description
subscribeCompletionHandler function handler to call. List inside is a granted QoS array
Source:
Returns:
current MQTT client instance
Type
MqttClient

unsubscribe(topic, unsubscribeSentHandler) → {MqttClient}

Unsubscribe from receiving messages on given topic
Parameters:
Name Type Description
topic string Topic you want to unsubscribe from
unsubscribeSentHandler function handler called after UNSUBSCRIBE packet sent
Source:
Returns:
current MQTT client instance
Type
MqttClient

unsubscribeCompletionHandler(unsubscribeCompletionHandler) → {MqttClient}

Sets handler which will be called after UNSUBACK packet receiving
Parameters:
Name Type Description
unsubscribeCompletionHandler function handler to call with the packetid
Source:
Returns:
current MQTT client instance
Type
MqttClient