Skip to main content

Class: OutboxDispatcher

Defined in: src/outbox/OutboxDispatcher.ts:32

Enterprise Transactional Outbox Engine for EntityTS. Guarantees zero message loss and at-least-once delivery between local database transactions and distributed message brokers (e.g. Kafka, RabbitMQ, SQS, Webhooks).

Constructors​

Constructor​

new OutboxDispatcher(adapter): OutboxDispatcher

Defined in: src/outbox/OutboxDispatcher.ts:35

Parameters​

ParameterType
adapterIDbAdapter

Returns​

OutboxDispatcher

Methods​

ensureSchema()​

ensureSchema(): Promise<void>

Defined in: src/outbox/OutboxDispatcher.ts:37

Returns​

Promise<void>


enqueue()​

enqueue<T>(eventType, payload, transaction?): Promise<string>

Defined in: src/outbox/OutboxDispatcher.ts:117

Enqueues a message into the outbox within the current database transaction. If the transaction commits, the message is guaranteed to be saved; if rolled back, nothing is emitted.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
eventTypestringDomain event type name (e.g. 'PAYMENT_RECEIVED', 'ORDER_CREATED').
payloadTArbitrary event data object or primitive.
transaction?DbTransactionOptional active DbTransaction instance.

Returns​

Promise<string>

Generated outbox message ID.


dispatchPending()​

dispatchPending(handler, options?): Promise<DispatchSummary>

Defined in: src/outbox/OutboxDispatcher.ts:160

Polls and dispatches pending outbox events through the provided delivery handler (e.g. Kafka producer). Updates message status to DISPATCHED or increments retry count on failure.

Parameters​

ParameterTypeDescription
handler(message) => Promise<void>Asynchronous message sender callback.
options?DispatchOptionsBatch size and max retry attempts.

Returns​

Promise<DispatchSummary>


getPendingCount()​

getPendingCount(): Promise<number>

Defined in: src/outbox/OutboxDispatcher.ts:240

Retrieves current pending message count in the outbox.

Returns​

Promise<number>