TemplateMongoDB client instance.
MongoDB database instance where the outbox will operate.
The outbox will create two collections in this database:
hermes_outbox_messages - Stores outgoing eventshermes_outbox_consumers - Stores consumer stateOptionalnowFunction that returns the current date/time.
Override this for testing with fixed timestamps.
OptionalonCallback invoked when a database error occurs.
Use this for logging, monitoring, or alerting on database issues.
OptionalonCallback invoked when event publishing fails.
Use this for logging, monitoring, or alerting on publish failures. Hermes will continue retrying the event after calling this callback.
OptionalpartitionPartition key for horizontal scaling.
Multiple consumers can run concurrently by using different partition keys. Events are filtered by partition key, allowing you to scale by tenant, region, etc.
Multi-tenant partitioning
// Tenant 1 consumer
const tenant1Outbox = createOutboxConsumer({
// ...
partitionKey: 'tenant-abc'
})
// Tenant 2 consumer
const tenant2Outbox = createOutboxConsumer({
// ...
partitionKey: 'tenant-xyz'
})
// Publish to specific partition
await tenant1Outbox.publish(event, async (session, db) => {
// Event goes to tenant-abc partition
})
Callback function invoked when Hermes delivers an event.
IMPORTANT: This callback MUST throw an error if publish fails. If it completes successfully, the event is considered delivered and won't be retried.
OptionalsaveWhether to save sentAt timestamps for each processed message.
⚠️ Use with caution: When true, Hermes will update each message document after
successful delivery, significantly increasing I/O operations and database load.
Only enable this if you need to track exact delivery times for debugging or auditing.
OptionalshouldWhether to automatically stop the consumer on SIGTERM/SIGINT signals.
When true, Hermes registers signal handlers to gracefully shutdown on process termination.
OptionalwaitWait time in milliseconds after a failed publish attempt before retrying.
Configuration parameters for creating a MongoDB outbox consumer.
Event - Type of events handled by the consumer (use discriminated unions for multiple event types)
Example
Basic configuration
Example
Full configuration with all options