UNPKG

@nestjs/microservices

Version:

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

76 lines (75 loc) • 3.9 kB
import { RmqContext } from '../ctx-host/index.js'; import { RmqEvents, RmqStatus } from '../events/rmq.events.js'; import { RmqUrl } from '../external/rmq-url.interface.js'; import { MessageHandler, RmqOptions, TransportId } from '../interfaces/index.js'; import { ReadPacket } from '../interfaces/packet.interface.js'; import { Server } from './server.js'; type AmqpConnectionManager = any; type ChannelWrapper = any; type Channel = any; /** * @publicApi */ export declare class ServerRMQ extends Server<RmqEvents, RmqStatus> { protected readonly options: Required<RmqOptions>['options']; transportId: TransportId; protected server: AmqpConnectionManager | null; protected channel: ChannelWrapper | null; protected connectionAttempts: number; protected readonly urls: string[] | RmqUrl[]; protected readonly queue: string; protected readonly noAck: boolean; protected readonly maxMessageSize: number; protected readonly queueOptions: any; protected readonly wildcardHandlers: Map<string, MessageHandler<any, any, any>>; protected pendingEventListeners: Array<{ event: keyof RmqEvents; callback: RmqEvents[keyof RmqEvents]; }>; constructor(options: Required<RmqOptions>['options']); listen(callback: (err?: unknown, ...optionalParams: unknown[]) => void): Promise<void>; close(): Promise<void>; start(callback?: (err?: unknown, ...optionalParams: unknown[]) => void): Promise<void>; createClient<T = any>(): Promise<T>; private registerConnectListener; private registerDisconnectListener; private registerBlockedListener; private registerUnblockedListener; setupChannel(channel: Channel, callback: Function): Promise<void>; handleMessage(message: Record<string, any>, channel: any): Promise<void>; /** * Skips a message whose body is larger than "maxMessageSize" without * decoding it: JSON.parse() can take dozens of times the size of the text * in memory, and V8 ends the process, instead of throwing, once the heap is * exhausted. Neither amqplib nor the broker's default limit bounds the body * below that. */ protected skipOversizedMessage(message: Record<string, any>, channel: any): Promise<void>; handleEvent(pattern: string, packet: ReadPacket, context: RmqContext): Promise<any>; sendMessage<T = any>(message: T, replyTo: any, correlationId: string, context: RmqContext): Promise<unknown>; unwrap<T>(): T; on<EventKey extends keyof RmqEvents = keyof RmqEvents, EventCallback extends RmqEvents[EventKey] = RmqEvents[EventKey]>(event: EventKey, callback: EventCallback): void; getHandlerByPattern(pattern: string): MessageHandler | null; /** * With "wildcards", the queue is bound to the service's exchange once per * handler pattern, so the broker routes a message published there by its * routing key, which is what its topic permissions are checked against, * and ClientRMQ sets that key to the pattern. The handler is picked by the * pattern in the body, so this checks that it is the handler of the routing * key as well. A message published to the queue itself, through another * exchange, or through the binding of the "routingKey" option is not * checked. */ protected isPatternOfRoutingKey(pattern: string, fields: Record<string, any> | undefined): boolean; /** * Returns the handler of a routing key, read as the broker routed it: as * JSON, '"admin.purge"' would name the handler of "admin.purge". ClientRMQ * sends an object pattern as the normalized JSON its handler is stored by. */ private getHandlerByRoutingKey; protected initializeSerializer(options: RmqOptions['options']): void; private parseMessageContent; protected initializeWildcardHandlersIfExist(): void; private matchRmqPattern; } export {};