TemplateSends a message or array of messages to the async outbox.
Messages are stored in the asyncOutbox table and processed via polling.
Unlike queue(), this doesn't use PostgreSQL Logical Replication.
When to use:
Single message or array of messages to send
Optionaloptions: PublishOptionsOptional transaction for atomic operations
// Send single compensation command
await outbox.send({
messageId: constructMessageId('RevertPayment', orderId),
messageType: 'RevertPayment',
message: { type: 'RevertPayment', data: { orderId } }
})
// Send multiple messages atomically
await outbox.send([compensationCmd1, compensationCmd2])
// Send within a transaction
await sql.begin(async (sql) => {
await updateSomething(sql)
await outbox.send(compensationCmd, { tx: sql })
})
Starts the async outbox consumer polling loop.
Begins polling the asyncOutbox table at the configured interval
for undelivered messages.
Stop function for graceful shutdown
Asynchronous outbox consumer for non-critical messages.
Unlike the main outbox (WAL-based via Logical Replication), the async outbox uses polling and is suitable for:
Key Differences from Main Outbox
Usage
The async outbox is typically created via useBasicAsyncOutboxConsumerPolicy and accessed through the main outbox consumer's
send()method.Message - The type of domain messages/events
Example
See