/** * @fileoverview Kafka connection management with singleton pattern * @description Manages all Kafka connections including producers, consumers, and admin clients */ import { Kafka, Producer, Consumer, Admin } from "kafkajs"; import { IKafkaConsumerOptions, KafkaConfig } from "../interface/kafka.interface"; /** * Manages Kafka connections and provides factory methods for producers, consumers, and admin clients. * * @description This class implements the singleton pattern to ensure consistent connection * management across the application. It handles: * - Kafka client initialization * - Producer creation and management * - Consumer creation and management * - Admin client management * - Graceful shutdown of all connections * * @example * ```typescript * const connectionManager = KafkaConnectionManager.getInstance(config); * const producer = await connectionManager.createProducer('my-producer'); * const consumer = await connectionManager.createConsumer('my-group'); * ``` */ export declare class KafkaConnectionManager { private config; private static instance; private kafka; private producers; private consumers; private admin; private logger; /** * Creates a new KafkaConnectionManager instance. * * @param config - Kafka configuration * @private */ constructor(config: KafkaConfig); /** * Gets or creates the singleton instance of KafkaConnectionManager. * * @param config - Kafka configuration * @returns The singleton KafkaConnectionManager instance */ static getInstance(config: KafkaConfig): KafkaConnectionManager; /** * Gets the underlying Kafka client instance. * * @returns The Kafka client instance */ getKafka(): Kafka; /** * Creates or retrieves a Kafka producer. * * @param producerId - Unique identifier for the producer * @returns Promise resolving to Producer instance or undefined if creation fails * * @description Creates a new producer if one doesn't exist with the given ID, * otherwise returns the existing producer. Producers are cached for reuse. */ createProducer(producerId: string): Promise; /** * Creates or retrieves a Kafka consumer. * * @param groupId - Consumer group ID * @param options - Optional consumer configuration * @returns Promise resolving to Consumer instance or undefined if creation fails * * @description Creates a new consumer if one doesn't exist with the given group ID, * otherwise returns the existing consumer. Consumers are cached for reuse. */ createConsumer(groupId: string, options?: IKafkaConsumerOptions): Promise; /** * Gets or creates the Kafka admin client. * * @returns Promise resolving to Admin client instance * * @description Creates and connects the admin client if it doesn't exist, * otherwise returns the existing connected admin client. */ getAdmin(): Promise; /** * Performs graceful shutdown of all Kafka connections. * * @returns Promise that resolves when all connections are closed * * @description Cleanly disconnects all producers, consumers, and admin clients. * This method should be called during application shutdown to prevent * resource leaks and ensure proper cleanup. * * @example * ```typescript * process.on('SIGTERM', async () => { * await connectionManager.shutdown(); * }); * ``` */ shutdown(): Promise; } //# sourceMappingURL=connection-manager.d.ts.map