Client constructor
The configuration for this client
Notifies the MQTT5 client that you want it to end connectivity to the configured endpoint, disconnecting any existing connection and halting reconnection attempts.
This is an asynchronous operation. Once the process completes, no further events will be emitted until the client has start invoked. Invoking start() after a stop() will always result in a new MQTT session.
Optional
disconnectPacket: DisconnectPacket(optional) properties of a DISCONNECT packet to send as part of the shutdown process
Subscribe to one or more topic filters by queuing a SUBSCRIBE packet to be sent to the server.
SUBSCRIBE packet to send to the server
a promise that will be rejected with an error or resolved with the SUBACK response
Unsubscribe from one or more topic filters by queuing an UNSUBSCRIBE packet to be sent to the server.
UNSUBSCRIBE packet to send to the server
a promise that will be rejected with an error or resolved with the UNSUBACK response
Send a message to subscribing clients by queuing a PUBLISH packet to be sent to the server.
PUBLISH packet to send to the server
a promise that will be rejected with an error or resolved with the PUBACK response (QoS 1) or undefined (QoS 0)
Registers a listener for the client's error event. An error event is emitted when the client encounters a serious error condition, such as invalid input, napi failures, and other potentially unrecoverable situations.
the type of event to listen to
the event listener to add
Registers a listener for the client's messageReceived event. A messageReceived event is emitted when an MQTT PUBLISH packet is received by the client.
the type of event to listen to
the event listener to add
Registers a listener for the client's attemptingConnect event. A attemptingConnect event is emitted every time the client begins a connection attempt.
the type of event to listen to
the event listener to add
Registers a listener for the client's connectionSuccess event. A connectionSuccess event is emitted every time the client successfully establishes an MQTT connection.
the type of event to listen to
the event listener to add
Registers a listener for the client's connectionFailure event. A connectionFailure event is emitted every time the client fails to establish an MQTT connection.
the type of event to listen to
the event listener to add
Registers a listener for the client's disconnection event. A disconnection event is emitted when the client's current MQTT connection is closed for any reason.
the type of event to listen to
the event listener to add
Registers a listener for the client's stopped event. A stopped event is emitted when the client finishes shutdown as a result of the user invoking stop.
the type of event to listen to
the event listener to add
Forces all written events to be buffered in memory. The buffered data will be flushed when uncork is called.
Flushes all data buffered since cork was called.
NOTE: It is HIGHLY recommended that uncorking should always be done via
process.nextTick
, not during the EventEmitter.on()
call.
Synchronously calls each of the listeners registered for the event key supplied in registration order. If the BufferedEventEmitter is currently corked, the event will be buffered until uncork is called.
The name of the event
Rest
...args: any[]Event payload
Static
ERROREvent emitted when the client encounters a serious error condition, such as invalid input, napi failures, and other potentially unrecoverable situations.
Listener type: ErrorEventListener
Static
MESSAGE_Event emitted when an MQTT PUBLISH packet is received by the client.
Listener type: MessageReceivedEventListener
Static
ATTEMPTING_Event emitted when the client begins a connection attempt.
Listener type: AttemptingConnectEventListener
Static
CONNECTION_Event emitted when the client successfully establishes an MQTT connection. Only emitted after an attemptingConnect event.
Listener type: ConnectionSuccessEventListener
Static
CONNECTION_Event emitted when the client fails to establish an MQTT connection. Only emitted after an attemptingConnect event.
Listener type: ConnectionFailureEventListener
Static
DISCONNECTIONEvent emitted when the client's current connection is closed for any reason. Only emitted after a connectionSuccess event.
Listener type: DisconnectionEventListener
Static
STOPPEDEvent emitted when the client finishes shutdown as a result of the user invoking stop.
Listener type: StoppedEventListener
Triggers cleanup of native resources associated with the MQTT5 client. Once this has been invoked, callbacks and events are not guaranteed to be received.
This must be called when finished with a client; otherwise, native resources will leak. It is not safe to invoke any further operations on the client after close() has been called.
For a running client, safe and proper shutdown can be accomplished by
const stopped = once(client, "stopped");
client.stop();
await stopped;
client.close();
This is an asynchronous operation.
Queries a small set of numerical statistics about the current state of the client's operation queue
Queries a small set of numerical statistics about the current state of the client's operation queue
use getOperationalStatistics instead
Generated using TypeDoc
Node.js specific MQTT5 client implementation
Not all parts of the MQTT5 spec are supported. We currently do not support:
MQTT5 Client User Guide
This client is based on native resources. When finished with the client, you must call close() to dispose of them or they will leak.