Skip to content

RmqRecordSerializer

reference
2 min readUpdated

Kind: Class

Source: packages/microservices/serializers/rmq-record.serializer.ts

Part of: Microservices

RmqRecordSerializer converts outgoing NestJS microservice packets into RabbitMQ-compatible record payloads. It preserves the request packet shape while extracting or merging RabbitMQ-specific metadata, such as headers and message properties, for transport delivery.

Implements: Serializer

Methods

MethodSignatureReturns
serializeserialize(packet: ReadPacket)ReadPacket & Partial<RmqRecord>

Diagram

mermaid
graph LR
  A[Application Message] --> B[RmqRecordSerializer]
  B --> C[ReadPacket]
  B --> D[Partial RmqRecord]
  C --> E[RabbitMQ Transport]
  D --> E

Usage

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

const serializer = new RmqRecordSerializer();

const packet = serializer.serialize({
  pattern: 'orders.created',
  data: {
    orderId: 'order_123',
    customerId: 'customer_456',
  },
});

client.send('orders.created', packet.data);

AI Coding Instructions

  • Use RmqRecordSerializer at the RabbitMQ transport boundary when outgoing packets may include RabbitMQ record metadata.
  • Preserve the standard NestJS ReadPacket fields, especially pattern and data, when extending serialization behavior.
  • Ensure RabbitMQ-specific options, such as headers or properties, are carried through without mutating the original payload.
  • Keep custom serializers compatible with the serialize(): ReadPacket & Partial<RmqRecord> return contract.
  • Test serialization with both plain message payloads and RmqRecord-style payloads containing transport metadata.

How it works

Relationships

  • IMPORTS → isObject

Was this page helpful?

Download as PDF
RmqRecordSerializer — NestJS head-to-head