UNPKG

@message-queue-toolkit/kafka

Version:
42 lines (41 loc) 1.52 kB
import { Duplex } from 'node:stream'; type CallbackFunction = (error?: Error | null) => void; type MessageWithTopicAndPartition = { topic: string; partition: number; }; export type KafkaMessageBatchOptions = { batchSize: number; timeoutMilliseconds: number; }; export type MessageBatch<TMessage> = { topic: string; partition: number; messages: TMessage[]; }; export interface KafkaMessageBatchStream<TMessage extends MessageWithTopicAndPartition> extends Duplex { on(event: string | symbol, listener: (...args: any[]) => void): this; on(event: 'data', listener: (chunk: MessageBatch<TMessage>) => void): this; push(chunk: MessageBatch<TMessage> | null): boolean; } /** * Collects messages in batches based on provided batchSize and flushes them when messages amount or timeout is reached. */ export declare class KafkaMessageBatchStream<TMessage extends MessageWithTopicAndPartition> extends Duplex { private readonly batchSize; private readonly timeout; private readonly currentBatchPerTopicPartition; private readonly batchTimeoutPerTopicPartition; constructor(options: { batchSize: number; timeoutMilliseconds: number; }); _read(): void; _write(message: TMessage, _encoding: BufferEncoding, callback: CallbackFunction): void; _final(callback: CallbackFunction): void; private flushAllBatches; private flushCurrentBatchMessages; private getTopicPartitionKey; private splitTopicPartitionKey; } export {};