@nestjs/microservices
Version:
Microservices for NestJS: message and event handlers over Kafka, RabbitMQ, NATS, Redis, MQTT, gRPC or TCP.
62 lines (61 loc) • 2.83 kB
TypeScript
import { EventEmitter } from 'events';
import { NatsContext } from '../ctx-host/nats.context.js';
import { NatsEvents, NatsStatus } from '../events/nats.events.js';
import { NatsOptions, TransportId } from '../interfaces/microservice-configuration.interface.js';
import { Server } from './server.js';
type Client = any;
type NatsMsg = any;
/**
* @publicApi
*/
export declare class ServerNats<E extends NatsEvents = NatsEvents, S extends NatsStatus = NatsStatus> extends Server<E, S> {
private readonly options;
transportId: TransportId;
private natsClient;
private closeCount;
protected statusEventEmitter: EventEmitter<{
disconnect: [data?: string | number | undefined];
reconnect: [data?: string | number | undefined];
update: [data?: string | number | import("../events/nats.events.js").ServersChangedEvent | undefined];
}>;
private subscriptions;
constructor(options: Required<NatsOptions>['options']);
listen(callback: (err?: unknown, ...optionalParams: unknown[]) => void): Promise<void>;
start(callback: (err?: unknown, ...optionalParams: unknown[]) => void): void;
bindEvents(client: Client): void;
close(): Promise<void>;
createNatsClient(): Promise<Client>;
getMessageHandler(channel: string): Function;
handleMessage(channel: string, natsMsg: NatsMsg): Promise<any>;
/**
* Whether the packet is a reply of a Nest server, which the default
* deserializer leaves as it is: a packet with an id that carries a
* response, an error or the end of the response stream instead of a
* pattern and data.
*/
private isReply;
/**
* Whether a message handler receives a request published to the subject as
* well. NATS delivers a message to every subscription whose subject matches
* it, but to a single member of a queue group.
*/
private isAnsweredByMessageHandler;
/**
* Whether a message handler subscribed to the subject itself receives a
* request published to it as well, as it does unless it shares a queue
* group with the given handler.
*/
private isAnsweredByOwnMessageHandler;
/**
* Whether a subject matches a subscription subject, in which "*" stands for
* any single token and a final ">" for one or more tokens.
*/
private matchNatsSubject;
getPublisher(natsMsg: NatsMsg, id: string, ctx: NatsContext): (response: any) => any;
handleStatusUpdates(client: Client): Promise<void>;
unwrap<T>(): T;
on<EventKey extends keyof E = keyof E, EventCallback extends E[EventKey] = E[EventKey]>(event: EventKey, callback: EventCallback): void;
protected initializeSerializer(options: NatsOptions['options']): void;
protected initializeDeserializer(options: NatsOptions['options']): void;
}
export {};