Skip to content

MqttRecordBuilder

reference
1 min readUpdated

Kind: Class

Source: packages/microservices/record-builders/mqtt.record-builder.ts

Part of: Microservices

MqttRecordBuilder constructs MqttRecord instances for MQTT message handling within the microservices transport layer. It provides a fluent API for configuring payload data, QoS, retain and duplicate flags, and MQTT v5 properties before creating an immutable record with build().

Methods

MethodSignatureReturns
setDatasetData(data: TData)this
setQoSsetQoS(qos: MqttRecordOptions['qos'])this
setRetainsetRetain(retain: MqttRecordOptions['retain'])this
setDupsetDup(dup: MqttRecordOptions['dup'])this
setPropertiessetProperties(properties: MqttRecordOptions['properties'])this
buildbuild()MqttRecord

Diagram

mermaid
graph LR
  A[Message Payload] --> B[MqttRecordBuilder]
  C[QoS / Retain / Dup Flags] --> B
  D[MQTT Properties] --> B
  B -->|build()| E[MqttRecord]
  E --> F[MQTT Transport / Broker]

Usage

ts
import { MqttRecordBuilder } from './mqtt.record-builder';

const record = new MqttRecordBuilder()
  .setData(Buffer.from(JSON.stringify({ event: 'order.created', orderId: '123' })))
  .setQoS(1)
  .setRetain(false)
  .setDup(false)
  .setProperties({
    contentType: 'application/json',
  })
  .build();

// Pass the record to the MQTT publishing or transport layer.

AI Coding Instructions

  • Use the fluent setter pattern: configure all required values through setData(), setQoS(), and optional MQTT flags before calling build().
  • Validate payload format and QoS values at the integration boundary; MQTT QoS must match the broker and client capabilities.
  • Use setRetain(true) only for messages intended to be stored by the broker and delivered to future subscribers.
  • Set dup only when handling MQTT redelivery behavior; it should not be used as a general retry indicator.
  • Keep MQTT v5 metadata in setProperties() and ensure property names and values are compatible with the MQTT client implementation.

Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (1)

  • MqttControllerintegration/microservices/src/mqtt/mqtt.controller.ts:16

Was this page helpful?

Download as PDF
MqttRecordBuilder — NestJS head-to-head