import { BulkWriteOptions, Collection, Document, OptionalUnlessRequiredId } from 'mongodb'; import { ErrorEvents } from './ErrorEvents'; import { Timeout } from './Timeout'; import { TypedEventEmitter } from './TypedEventEmitter'; export interface BatchPublisherOptions { /** * Maximum number of messages per batch to bulk insert. */ maxBatchSize?: number; /** * Delay before a batch insert. */ batchDelayMs?: number; /** * With `bestEffort: true` (default), * * - batches are inserted with write concern `majority`, * - the `BatchPublisher` will emit `error` events on write failures, * - retry inserting messages, * - and attempt a bulk insert on closure. * * With `bestEffort: false`, * * - batches are inserted with write concern `0`, * - no errors will be emitted on failures, * - and unwritten messages will be dropped in case of failure or closure. */ bestEffort?: boolean; bulkWriteOptions?: BulkWriteOptions; } export type BatchPublisherEvents = ErrorEvents; export declare class BatchPublisher extends TypedEventEmitter> { protected collection: Collection; protected maxBatchSize: number; protected delayMs: number; protected bestEffort: boolean; protected bulkWriteOptions: BulkWriteOptions; protected queue: OptionalUnlessRequiredId[]; protected flushTimeout: Timeout; protected closed: boolean; constructor(collection: Collection, options?: BatchPublisherOptions); /** * Publish a message after a delay. * See `options.bestEffort` for behavior. */ publish(message: OptionalUnlessRequiredId): void; close(): Promise; protected flush(): Promise; }