/** * @fileoverview Main entry point for js-kafka library * @description Provides a comprehensive Kafka client for dynamic topic management, * message production, and consumption in microservice architectures. * * @author js-kafka Team * @version 1.0.0 */ import { IGetKafkaClientOptions, KafkaConfig } from "./interface/kafka.interface"; import { KafkaTopicHandlerRegistry } from "./kafka/handler-registry"; import { KafkaProducerManager } from "./kafka/producer-manager"; /** * Main Kafka client class that orchestrates all Kafka operations. * * @description This class provides a unified interface for Kafka operations including: * - Dynamic topic creation and management * - Message production with automatic topic creation * - Consumer registration and management * - Graceful shutdown and cleanup * * @example * ```typescript * const kafka = new KafkaClient({ * env: 'dev', * brokers: ['localhost:9092'], * clientId: 'my-service', * serviceName: 'user-service', * consumerGroupId: 'user-service-group' * }); * * await kafka.init(); * ``` */ export declare class KafkaClient { private readonly config; private readonly logger; private readonly connection; private readonly consumer; readonly producer: KafkaProducerManager; private readonly admin; readonly registry: KafkaTopicHandlerRegistry; private isInitialized; private static instance; /** * Creates a new KafkaClient instance. * * @param kafkaConfig - Configuration object for Kafka client * @description Initializes all Kafka components and sets up circular dependencies. * The configuration is validated and merged with defaults. * * @example * ```typescript * const client = new KafkaClient({ * env: 'production', * brokers: ['kafka1:9092', 'kafka2:9092'], * clientId: 'payment-service', * serviceName: 'payment-service', * consumerGroupId: 'payment-consumers', * partitions: 3, * replicationFactor: 2 * }); * ``` */ constructor(kafkaConfig: KafkaConfig); /** * Gets or creates a singleton instance of KafkaClient. * * @param kafkaConfig - Configuration object for Kafka client * @returns The singleton KafkaClient instance * * @description Implements the singleton pattern to ensure only one KafkaClient * instance exists per application. Subsequent calls return the same instance. * * @example * ```typescript * const kafka1 = KafkaClient.getInstance(config); * const kafka2 = KafkaClient.getInstance(config); * console.log(kafka1 === kafka2); // true * ``` */ static getInstance(kafkaConfig: KafkaConfig): KafkaClient; /** * Initializes the Kafka client and all its components. * * @returns Promise that resolves when initialization is complete * @throws Error if initialization fails * * @description This method must be called after registering all consumers * and before sending any messages. It performs the following operations: * 1. Registers the topic-updates handler for dynamic subscription * 2. Populates the topic map with existing topics * 3. Initializes all consumers * 4. Sets the initialized flag * * @example * ```typescript * // Register consumers first * kafka.registry.registerSingle('user-events', handleUserEvents); * * // Then initialize * await kafka.init(); * * // Now ready to send messages * await kafka.producer.sendMessage('user-events', message, 'user123'); * ``` */ init(): Promise; /** * Performs graceful shutdown of the Kafka client. * * @returns Promise that resolves when shutdown is complete * * @description Cleanly shuts down all Kafka connections including: * - All consumer connections * - All producer connections * - Admin client connections * - Connection manager cleanup * * This method should be called when the application is shutting down * to ensure proper cleanup and prevent resource leaks. * * @example * ```typescript * process.on('SIGTERM', async () => { * await kafka.shutdown(); * process.exit(0); * }); * ``` */ shutdown(): Promise; createTopicPublic(topicName: string, serviceName: string, entityId: string, numPartitions?: number, replicationFactor?: number): Promise; sendPublicTopicUpdate(topicName: string, serviceName: string, entityId: string): Promise; } /** * Factory function to create or get a KafkaClient instance. * * @param kafkaConfig - Configuration object for Kafka client * @param options - Optional configuration for client creation behavior * @returns KafkaClient instance (singleton or new instance based on options) * * @description This is the recommended way to create a KafkaClient instance. * By default, it returns a singleton instance, but can be configured to create * new instances for testing or special use cases. * * @example * ```typescript * // Get singleton instance (default behavior) * const kafka = getKafkaClient(config); * * // Create new instance for testing * const testKafka = getKafkaClient(config, { isSingletonEnabled: false }); * * // Explicit singleton * const singletonKafka = getKafkaClient(config, { isSingletonEnabled: true }); * ``` */ export declare function getKafkaClient(kafkaConfig: KafkaConfig, options?: IGetKafkaClientOptions): KafkaClient; export * from "./interface/kafka.interface"; export { KafkaConfigManager } from "./config/kafka-config"; export { TopicHandlerTypes } from "./enums/kafka.enums"; //# sourceMappingURL=index.d.ts.map