Template
Interface for the MongoDB Outbox Consumer.
This is the main interface for interacting with Hermes MongoDB. It provides methods for:
Event - Type of events handled by the consumer (use discriminated unions for multiple event types)
Basic consumer setup
type DomainEvent = | { type: 'MedicineAssigned'; patientId: string; medicineId: string } | { type: 'TaskCompleted'; taskId: string; completedAt: Date }const outbox = createOutboxConsumer<DomainEvent>({ client, db: client.db('hospital'), publish: async (event) => { await messageBroker.publish(event) }})// Start consumingconst stop = await outbox.start()// Publish eventsawait outbox.publish({ type: 'MedicineAssigned', patientId: 'patient-123', medicineId: 'med-456'}, async (session, db) => { await db.collection('assignments').insertOne({ ... }, { session })}) Copy
type DomainEvent = | { type: 'MedicineAssigned'; patientId: string; medicineId: string } | { type: 'TaskCompleted'; taskId: string; completedAt: Date }const outbox = createOutboxConsumer<DomainEvent>({ client, db: client.db('hospital'), publish: async (event) => { await messageBroker.publish(event) }})// Start consumingconst stop = await outbox.start()// Publish eventsawait outbox.publish({ type: 'MedicineAssigned', patientId: 'patient-123', medicineId: 'med-456'}, async (session, db) => { await db.collection('assignments').insertOne({ ... }, { session })})
Publishes event(s) to the outbox with optional transactional consistency
Starts the consumer and begins processing events via Change Streams
Creates a transaction scope for publishing multiple events atomically
Interface for the MongoDB Outbox Consumer.
This is the main interface for interacting with Hermes MongoDB. It provides methods for:
Event - Type of events handled by the consumer (use discriminated unions for multiple event types)
Example
Basic consumer setup
See