# RmqRecordOptions

**Kind:** Interface

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

**Part of:** [Microservices](subsystem-packages-microservices)

`RmqRecordOptions` defines RabbitMQ message properties used when building a record for publishing through the microservices layer. It controls message lifetime, routing metadata, delivery behavior, content metadata, and custom headers passed to the RabbitMQ broker.

## Properties

| Property | Type |
|---|---|
| `expiration` | `string | number` |
| `userId` | `string` |
| `CC` | `string | string[]` |
| `mandatory` | `boolean` |
| `persistent` | `boolean` |
| `deliveryMode` | `boolean | number` |
| `BCC` | `string | string[]` |
| `contentType` | `string` |
| `contentEncoding` | `string` |
| `headers` | `Record<string, string>` |
| `priority` | `number` |
| `messageId` | `string` |
| `timestamp` | `number` |
| `type` | `string` |
| `appId` | `string` |

## Diagram

```mermaid
graph LR
  A[Application Message] --> B[RmqRecordOptions]
  B --> C[RMQ Record Builder]
  C --> D[RabbitMQ Publish Properties]

  B --> E[Routing: CC / BCC]
  B --> F[Delivery: mandatory / persistent / deliveryMode]
  B --> G[Metadata: contentType / contentEncoding / headers]
  B --> H[Lifetime: expiration]
```

## Usage

```ts
import type { RmqRecordOptions } from './rmq.record-builder';

const options: RmqRecordOptions = {
  expiration: 60_000,
  userId: 'notification-service',
  CC: ['audit.queue'],
  BCC: 'internal-monitoring.queue',
  mandatory: true,
  persistent: true,
  deliveryMode: 2,
  contentType: 'application/json',
  contentEncoding: 'utf-8',
  headers: {
    'x-request-id': 'req_123456',
    'x-message-source': 'notifications',
  },
};

// Pass options to the RMQ record/message builder used by your publisher.
```

## AI Coding Instructions

- Provide all required properties when creating `RmqRecordOptions`; use `headers: {}` when no custom headers are needed.
- Use `expiration` as a millisecond value or RabbitMQ-compatible string, and ensure it matches the intended message TTL behavior.
- Use `CC` and `BCC` for additional broker routing targets; provide either a single queue name or an array of queue names.
- Prefer `deliveryMode: 2` and `persistent: true` for messages that should survive broker restarts.
- Keep `headers` values as strings, serializing complex values before assigning them.
