@nestjs/microservices
Version:
Microservices for NestJS: message and event handlers over Kafka, RabbitMQ, NATS, Redis, MQTT, gRPC or TCP.
86 lines (85 loc) • 4.2 kB
TypeScript
import { Observable } from 'rxjs';
import { KafkaStatus } from '../events/index.js';
import { BrokersFunction, Consumer, ConsumerGroupJoinEvent, EachMessagePayload, Kafka, Producer, TopicPartitionOffsetAndMetadata } from '../external/kafka.interface.js';
import { KafkaParser } from '../helpers/index.js';
import { ClientKafkaProxy, KafkaOptions, OutgoingEvent, PacketMetadata, ReadPacket, WritePacket } from '../interfaces/index.js';
import { ClientProxy } from './client-proxy.js';
import { Logger } from '@nestjs/common';
/**
* @publicApi
*/
export declare class ClientKafka extends ClientProxy<never, KafkaStatus> implements ClientKafkaProxy {
protected readonly options: Required<KafkaOptions>['options'];
protected logger: Logger;
protected client: Kafka | null;
protected parser: KafkaParser | null;
protected initialized: Promise<void> | null;
protected responsePatterns: string[];
protected consumerAssignments: {
[key: string]: number;
};
protected brokers: string[] | BrokersFunction;
protected clientId: string;
protected groupId: string;
protected producerOnlyMode: boolean;
protected _consumer: Consumer | null;
protected _producer: Producer | null;
get consumer(): Consumer;
get producer(): Producer;
constructor(options: Required<KafkaOptions>['options']);
subscribeToResponseOf(pattern: unknown): void;
close(): Promise<void>;
handleClose(): void;
connect(): Promise<Producer>;
/**
* Tears down whatever a failed connection attempt managed to create, so a
* consumer that joined its group before the producer failed does not stay
* behind when the next attempt creates a new one. The client's state is only
* reset if no newer attempt has replaced it in the meantime (e.g., `close()`
* followed by `connect()` while the failed attempt was still pending).
*/
private discardPartialConnection;
private initializeClientAndConnections;
bindTopics(): Promise<void>;
createClient<T = any>(): Promise<T>;
createResponseCallback(): (payload: EachMessagePayload) => any;
getConsumerAssignments(): {
[key: string]: number;
};
emitBatch<TResult = any, TInput = any>(pattern: any, data: {
messages: TInput[];
}): Observable<TResult>;
commitOffsets(topicPartitions: TopicPartitionOffsetAndMetadata[]): Promise<void>;
unwrap<T>(): T;
on<EventKey extends string | number | symbol = string | number | symbol, EventCallback = any>(event: EventKey, callback: EventCallback): void;
protected registerConsumerEventListeners(): void;
protected registerProducerEventListeners(): void;
protected dispatchBatchEvent<TInput = any>(packets: ReadPacket<{
messages: TInput[];
}>): Promise<any>;
protected dispatchEvent(packet: OutgoingEvent): Promise<any>;
protected getReplyTopicPartition(topic: string): string;
protected publish(partialPacket: ReadPacket, callback: (packet: WritePacket) => any): () => void;
protected getResponsePatternName(pattern: string): string;
/**
* Adds the metadata a dispatch hook attached to a packet to the headers of
* a serialized message, under every name the message does not set itself.
* Returns a copy, as the message may be the caller's own record.
*/
protected mergeMetadata<T extends {
headers?: Record<string, any>;
}>(message: T, metadata: PacketMetadata | undefined): T;
/**
* Returns a copy of an event's message without the headers that make
* ServerKafka take a message with a correlation id for a request, and
* publish its response to the topic they name. The headers of an event can
* come from the data it forwards (an object with a "value" is sent as the
* message it describes), so they cannot ask for a reply.
*/
protected withoutReplyHeaders<T extends {
headers?: Record<string, any>;
}>(message: T): T;
protected setConsumerAssignments(data: ConsumerGroupJoinEvent): void;
protected initializeSerializer(options: KafkaOptions['options']): void;
protected initializeDeserializer(options: KafkaOptions['options']): void;
}