Hermes MongoDB
    Preparing search index...

    Type Alias OutboxConsumer<Event>Template

    Interface for the MongoDB Outbox Consumer.

    This is the main interface for interacting with Hermes MongoDB. It provides methods for:

    • Starting/stopping the consumer
    • Publishing events with transactional consistency
    • Scoping multiple event publishes to a single transaction

    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 consuming
    const stop = await outbox.start()

    // Publish events
    await outbox.publish({
    type: 'MedicineAssigned',
    patientId: 'patient-123',
    medicineId: 'med-456'
    }, async (session, db) => {
    await db.collection('assignments').insertOne({ ... }, { session })
    })
    type OutboxConsumer<Event extends OutboxEvent> = {
        publish: Publish<Event>;
        start: Start;
        withScope: WithScope<Event>;
    }

    Type Parameters

    Index

    Properties

    publish: Publish<Event>

    Publishes event(s) to the outbox with optional transactional consistency

    start: Start

    Starts the consumer and begins processing events via Change Streams

    withScope: WithScope<Event>

    Creates a transaction scope for publishing multiple events atomically