@logistically/events
Version:
A production-ready event-driven architecture library for NestJS with Redis Streams, comprehensive batching, reliable consumption, and enterprise-grade features.
45 lines (44 loc) • 1.69 kB
TypeScript
import { EventPublisherOptions } from './index';
import { EventValidator } from '../event-types';
import { BatchMessage, BatchConfig, BatchingTypeStrategy } from './batching-strategy';
import { TransportType } from './strategies/strategy-factory';
export { BatchConfig, BatchMessage, BatchEnvelope, BatchingTypeStrategy } from './batching-strategy';
export interface BatchedEventPublisherOptions extends EventPublisherOptions {
batchConfig?: BatchConfig;
transportType?: TransportType;
typePrefix?: string;
batchingTypeStrategy?: BatchingTypeStrategy;
}
export declare class BatchedEventPublisher {
private basePublisher;
private batchConfig;
private strategy;
private queues;
private failedMessages;
private activeBatches;
private readonly MAX_FAILED_MESSAGES;
private readonly MAX_QUEUES;
private readonly QUEUE_CLEANUP_INTERVAL;
private lastQueueCleanup;
constructor(transports: Record<string, any>, options: BatchedEventPublisherOptions);
get validator(): EventValidator;
addMessage<T>(eventType: string, body: T): Promise<void>;
publishBatch<T>(eventType: string, bodies: T[]): Promise<void>;
flush(): Promise<void>;
getFailedMessages(): BatchMessage[];
clearFailedMessages(): void;
private addToFailedMessages;
private cleanupEmptyQueues;
cleanup(): void;
close(): Promise<void>;
getMemoryStats(): {
queueCount: number;
totalMessages: number;
failedMessageCount: number;
activeBatches: number;
};
cleanupOldFailedMessages(maxAgeMs?: number): void;
private sendBatch;
private getEventTypePrefix;
private getTransportForBatch;
}