import type DomainMessage from "../../Domain/Event/DomainMessage"; import type EventListener from "../EventBus/EventListener"; import type EventSubscriber from "../EventBus/EventSubscriber"; import type IEventBus from "../EventBus/IEventBus"; import type { DomainEventConstructor } from "../EventBus/IEventBus"; import type IDeadLetterQueue from "./IDeadLetterQueue"; import type RetryPolicy from "./RetryPolicy"; /** * An EventBus implementation that catches handler failures and sends them to a dead letter queue. * Supports retry policies for automatic retry attempts before moving to DLQ. * * This class does not extend EventBus to avoid private property conflicts; * instead, it implements the IEventBus interface with DLQ support. */ export default class DeadLetterAwareEventBus implements IEventBus { private readonly deadLetterQueue; private readonly retryPolicy?; private readonly subscribersRegistry; private readonly listenersRegistry; constructor(deadLetterQueue: IDeadLetterQueue, retryPolicy?: RetryPolicy | undefined); publish(message: DomainMessage): Promise; attach(event: DomainEventConstructor, subscriber: EventSubscriber): DeadLetterAwareEventBus; addListener(listener: EventListener): DeadLetterAwareEventBus; /** * Retry a failed message from the dead letter queue * @param messageId The ID of the message to retry * @param handler The handler function to use for retry * @returns True if retry was successful, false otherwise */ retry(messageId: string, handler: (message: DomainMessage) => Promise | void): Promise; /** * Get the dead letter queue instance */ getDeadLetterQueue(): IDeadLetterQueue; /** * Safely execute a handler, catching errors and sending failures to the DLQ */ private safeExecute; private delay; private subscribersFor; }