Kind: Interface
Source: packages/microservices/external/mqtt-options.interface.ts
Part of: Microservices
MqttClientOptions defines connection and protocol settings for an MQTT client used by the microservices transport layer. It supports direct MQTT/TCP connections as well as WebSocket-based MQTT transports, including client identity, keepalive behavior, and WebSocket-specific options.
Properties
| Property | Type |
|---|---|
port | number |
host | string |
hostname | string |
path | string |
protocol | `'wss' |
wsOptions | { [x: string]: any; } |
keepalive | number |
clientId | string |
protocolId | string |
protocolVersion | number |
clean | boolean |
reconnectPeriod | number |
connectTimeout | number |
username | string |
password | string |
incomingStore | any |
outgoingStore | any |
queueQoSZero | boolean |
properties | { sessionExpiryInterval?: number; receiveMaximum?: number; maximumPacketSize?: number; topicAliasMaximum?: number; requestResponseInformation?: boolean; requestProblemInformation?: boolean; userProperties?: object; authenticationMethod?: string; authenticationData?: any; } |
reschedulePings | boolean |
servers | Array<{ host: string; port: number; }> |
resubscribe | boolean |
will | { topic: string; payload: string; qos: QoS; retain: boolean; } |
transformWsUrl | (url: string, options: any, client: any) => string |
Diagram
mermaidgraph LR Client[Microservice MQTT Client] --> Options[MqttClientOptions] Options --> Connection[host / hostname / port / path] Options --> Transport[protocol] Options --> Identity[clientId] Options --> Protocol[protocolId / protocolVersion] Options --> Keepalive[keepalive] Options --> WebSocket[wsOptions] Transport --> MQTT[mqtt / mqtts / tcp / ssl] Transport --> WS[ws / wss / wx / wxs] WebSocket --> WS
Usage
tsimport type { MqttClientOptions } from './mqtt-options.interface';
const mqttOptions: MqttClientOptions = {
host: 'broker.example.com',
hostname: 'broker.example.com',
port: 8883,
path: '/mqtt',
protocol: 'mqtts',
clientId: 'orders-service',
protocolId: 'MQTT',
protocolVersion: 4,
keepalive: 60,
wsOptions: {},
};
// Pass mqttOptions to the MQTT client or microservice transport configuration.
AI Coding Instructions
- Provide a valid
protocolvalue that matches the target transport, such asmqttsfor secure TCP orwssfor secure WebSockets. - Keep
host/hostname,port, andpathconsistent with the MQTT broker endpoint;pathis especially important for WebSocket connections. - Use a stable, unique
clientIdper running service instance to avoid broker-side client session conflicts. - Set
protocolIdandprotocolVersionto values supported by the broker; common MQTT settings areMQTTand version4. - Only populate
wsOptionswhen using a WebSocket-based protocol and pass broker-required headers, TLS options, or proxy configuration there.
How it works
MqttClientOptions is a TypeScript interface that describes MQTT connection options. It extends ISecureClientOptions, so its shape includes optional TLS key, certificate, CA, and rejectUnauthorized fields. mqtt-options.interface.ts:8 mqtt-options.interface.ts:136-150
All of its fields are optional. The declaration itself contains no runtime validation, defaults assignment, error throwing, or side effects. mqtt-options.interface.ts:8-135
Was this page helpful?