UNPKG

@nestjs/microservices

Version:

Microservices for NestJS: message and event handlers over Kafka, RabbitMQ, NATS, Redis, MQTT, gRPC or TCP.

42 lines (41 loc) • 1.17 kB
import { isObject } from '@nestjs/common/internal'; import { toPacketMetadata } from '../utils/packet-metadata.utils.js'; import { BaseRpcContext } from './base-rpc.context.js'; /** * @publicApi */ export class RmqContext extends BaseRpcContext { constructor(args) { super(args); } /** * Returns the original message (with properties, fields, and content). */ getMessage() { return this.args[0]; } /** * Returns the reference to the original RMQ channel. */ getChannelRef() { return this.args[1]; } /** * Returns the name of the pattern. */ getPattern() { return this.args[2]; } /** * Returns the message's `headers` property as packet metadata: what the * client attached to the packet, and every other header with a string * value. Headers of any other type (numbers, tables, arrays) are only * available through `getMessage()`. */ getMetadata() { const headers = this.args[0]?.properties?.headers; return isObject(headers) ? toPacketMetadata(Object.entries(headers)) : undefined; } }