/** * @fileoverview Kafka message production with automatic topic creation * @description Handles sending messages to Kafka topics with support for both single and batch operations */ import { IKafkaProducerOptions, KafkaConfig, MessagePayload } from "../interface/kafka.interface"; import { KafkaConnectionManager } from "./connection-manager"; import { KafkaAdminManager } from "./admin-manager"; /** * Manages Kafka message production with automatic topic creation. * * @description This class handles sending messages to Kafka topics with: * - Automatic topic creation using the naming convention * - Support for single and batch message sending * - Proper message formatting and header handling * - Integration with admin manager for topic management * - Configurable acknowledgment settings * * @example * ```typescript * const producer = KafkaProducerManager.getInstance(connection, config); * await producer.sendMessage('user-events', message, 'user123'); * await producer.sendBatchMessages('notifications', messages, 'batch1'); * ``` */ export declare class KafkaProducerManager { private connection; private config; private static _instance; private logger; private _config; private admin; /** * Creates a new KafkaProducerManager instance. * * @param connection - Kafka connection manager * @param config - Kafka configuration * @private */ constructor(connection: KafkaConnectionManager, config: KafkaConfig); /** * Gets or creates the singleton instance of KafkaProducerManager. * * @param connection - Kafka connection manager instance * @param config - Kafka configuration * @returns The singleton KafkaProducerManager instance */ static getInstance(connection: KafkaConnectionManager, config: KafkaConfig): KafkaProducerManager; /** * Sets the admin manager for topic creation. * * @param admin - Admin manager instance * * @description Creates a circular dependency with the admin manager * to enable automatic topic creation when sending messages. */ setAdmin(admin: KafkaAdminManager): void; /** * Sends a single message to a Kafka topic. * * @param topic - Base topic name (will be transformed using naming convention) * @param message - Message payload to send * @param entityId - Entity identifier for topic naming and partitioning * @param options - Optional producer configuration * @returns Promise that resolves when message is sent * @throws Error if message sending fails * * @description Sends a message to a topic using the internal naming convention. * The topic will be automatically created if it doesn't exist. Message headers * are properly formatted for Kafka compatibility. * * @example * ```typescript * await producer.sendMessage('user-events', { * key: 'user-123', * value: { action: 'login', timestamp: Date.now() }, * headers: { source: 'auth-service' } * }, 'user-123', { acks: -1 }); * ``` */ sendMessage(topic: string, message: MessagePayload, entityId?: string, options?: IKafkaProducerOptions): Promise; /** * Sends multiple messages to a Kafka topic in a single batch. * * @param topic - Base topic name (will be transformed using naming convention) * @param messages - Array of message payloads to send * @param entityId - Entity identifier for topic naming and partitioning * @param options - Optional producer configuration * @returns Promise that resolves when all messages are sent * @throws Error if batch sending fails * * @description Sends multiple messages in a single batch operation for better * throughput. The topic will be automatically created if it doesn't exist. * All messages are formatted and sent together to improve performance. * * @example * ```typescript * const messages = [ * { key: 'user-1', value: { action: 'login' } }, * { key: 'user-2', value: { action: 'logout' } } * ]; * await producer.sendBatchMessages('user-events', messages, 'batch-1'); * ``` */ sendBatchMessages(topic: string, messages: MessagePayload[], entityId?: string, options?: IKafkaProducerOptions): Promise; /** * Formats message headers for Kafka compatibility. * * @param headers - Raw headers object * @returns Formatted headers with string or Buffer values * @private * * @description Converts header values to strings or preserves Buffers * to ensure compatibility with Kafka's header format requirements. */ private formatHeaders; } //# sourceMappingURL=producer-manager.d.ts.map