# RmqRecordBuilder

**Kind:** Class

**Source:** [`packages/microservices/record-builders/rmq.record-builder.ts`](https://github.com/nestjs/nest/blob/master/packages/microservices/record-builders/rmq.record-builder.ts#L35)

**Part of:** [Microservices](subsystem-packages-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

| Method | Signature | Returns |
|---|---|---|
| `setOptions` | `setOptions(options: RmqRecordOptions)` | `this` |
| `setData` | `setData(data: TData)` | `this` |
| `build` | `build()` | `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)

- `RMQController` — `integration/microservices/src/rmq/rmq.controller.ts`:16
