Skip to content

RmqRecordBuilder

reference
1 min readUpdated

Kind: Class

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

Part of: Microservices

RmqRecordBuilder constructs RmqRecord instances for RabbitMQ-based microservice messages. It provides a fluent API for attaching message data and RabbitMQ publishing options before producing the final record with build().

Methods

MethodSignatureReturns
setOptionssetOptions(options: RmqRecordOptions)this
setDatasetData(data: TData)this
buildbuild()RmqRecord

Diagram

mermaid
graph LR
  A[Application message data] --> B[RmqRecordBuilder]
  C[RabbitMQ publish options] --> B
  B -->|setData() / setOptions()| D[Configured builder]
  D -->|build()| E[RmqRecord]
  E --> F[RMQ client transport]

Usage

ts
import { RmqRecordBuilder } from '@nestjs/microservices';

const record = new RmqRecordBuilder()
  .setData({
    event: 'order.created',
    orderId: 'order-123',
  })
  .setOptions({
    persistent: true,
    headers: {
      'x-correlation-id': 'request-456',
    },
  })
  .build();

// Example: publish through an injected NestJS ClientProxy
client.emit('orders.events', record);

AI Coding Instructions

  • Use the fluent chain setData(...).setOptions(...).build() when creating RabbitMQ records.
  • Call build() only after providing the payload required by the receiving consumer.
  • Keep transport-specific settings, such as persistent and message headers, in setOptions() rather than mixing them into the data payload.
  • Pass the built RmqRecord to RMQ-enabled ClientProxy methods such as emit() or send().

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)

  • RMQControllerintegration/microservices/src/rmq/rmq.controller.ts:16

Was this page helpful?

Download as PDF
RmqRecordBuilder — NestJS head-to-head