Skip to content

IClientPublishOptions

reference
1 min readUpdated

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

PropertyType
qosQoS
retainboolean
dupboolean

Diagram

mermaid
graph 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

ts
import { 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 qos according to delivery requirements: 0 for best-effort, 1 for at-least-once delivery, and 2 for exactly-once delivery.
  • Use retain: true only for topics where new subscribers should receive the latest published state.
  • Keep dup as false for 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?

Download as PDF
IClientPublishOptions — NestJS head-to-head