@rxap/nest-rabbitmq
Version:
This package provides a NestJS module for integrating with RabbitMQ using exchanges. It offers a client and server implementation for message queuing and supports features like health checks and error serialization. It simplifies the process of setting up
34 lines (33 loc) • 2.08 kB
TypeScript
import { LoggerService } from '@nestjs/common';
import { CustomTransportStrategy, MessageHandler, ReadPacket, RmqContext, Server, WritePacket } from '@nestjs/microservices';
import { ServerRmqOptions } from './options';
import { ChannelWrapper } from 'amqp-connection-manager';
import type { IAmqpConnectionManager } from 'amqp-connection-manager/dist/types/AmqpConnectionManager';
import { Observable, Subscription } from 'rxjs';
import { ErrorSerializer } from './error.serializer';
export declare const TRANSPORT_ID: unique symbol;
export declare class ServerRMQ extends Server implements CustomTransportStrategy {
protected readonly options: ServerRmqOptions;
protected readonly logger: LoggerService;
readonly transportId: symbol;
protected server: IAmqpConnectionManager | null;
protected channel: ChannelWrapper | null;
protected connectionAttempts: number;
protected queue: string;
protected errorSerializer: ErrorSerializer;
constructor(options: ServerRmqOptions, logger?: LoggerService);
listen(callback: (err?: unknown, ...optionalParams: unknown[]) => void): Promise<void>;
close(): void;
bindQueue(exchange: string, routingKey: string): Promise<void>;
start(callback?: (err?: unknown, ...optionalParams: unknown[]) => void): Promise<void>;
send(stream$: Observable<any>, respond: (data: WritePacket) => unknown | Promise<unknown>): Subscription;
createClient(): IAmqpConnectionManager;
setupChannel(channel: ChannelWrapper, callback?: () => any): Promise<void>;
handleMessage(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): void;
addHandler(pattern: any, callback: MessageHandler, isEventHandler?: boolean, extras?: Record<any, any>): void;
protected initializeDeserializer(options: ServerRmqOptions): void;
protected initializeSerializer(options: ServerRmqOptions): void;
private parseMessageContent;
}