Kind: Interface
Source: packages/microservices/external/mqtt-options.interface.ts
Part of: Microservices
IClientPublishOptions defines MQTT-specific options applied when publishing a message from a microservice client. It controls the delivery quality of service, whether the broker retains the message, and whether the message is marked as a duplicate delivery.
Properties
| Property | Type |
|---|---|
qos | QoS |
retain | boolean |
dup | boolean |
Diagram
mermaidgraph LR Client[MQTT Client] -->|publish topic + payload| Options[IClientPublishOptions] Options --> QoS[qos: QoS] Options --> Retain[retain: boolean] Options --> Duplicate[dup: boolean] Options --> Broker[MQTT Broker]
Usage
tsimport { IClientPublishOptions } from '@nestjs/microservices';
const publishOptions: IClientPublishOptions = {
qos: 1,
retain: true,
dup: false,
};
client.publish(
'devices/thermostat/status',
JSON.stringify({ temperature: 21.5 }),
publishOptions,
);
AI Coding Instructions
- Set
qosaccording to delivery requirements:0for best-effort,1for at-least-once delivery, and2for exactly-once delivery. - Use
retain: trueonly for topics where new subscribers should receive the latest published state. - Keep
dupasfalsefor normal publishes; set it only when explicitly retransmitting a previously sent MQTT message. - Pass these options to the underlying MQTT client's publish operation when implementing custom transport or client behavior.
Was this page helpful?