Type Alias ConsumerCreationParams<Event>Template

ConsumerCreationParams<Event>: {
    client: MongoClient;
    db: Db;
    now?: NowFunction;
    onDbError?: ErrorCallback;
    onFailedPublish?: ErrorCallback;
    partitionKey?: string;
    publish: ((event: Event) => AsyncOrSync<void> | never);
    saveTimestamps?: boolean;
    shouldDisposeOnSigterm?: boolean;
    waitAfterFailedPublishMs?: number;
}

Creation parameters of OutboxConsumer.

Type Parameters

  • Event

Type declaration

  • client: MongoClient
  • db: Db
  • Optionalnow?: NowFunction

    () => new Date()

  • OptionalonDbError?: ErrorCallback

    noop

  • OptionalonFailedPublish?: ErrorCallback

    noop

  • OptionalpartitionKey?: string

    default

  • publish: ((event: Event) => AsyncOrSync<void> | never)
      • (event): AsyncOrSync<void> | never
      • Parameters

        Returns AsyncOrSync<void> | never

  • OptionalsaveTimestamps?: boolean

    Use with consciously and carefully. When true, Hermes will be affecting many documents, resulting in much more I/O operations.

    false
    
  • OptionalshouldDisposeOnSigterm?: boolean
    true
    
  • OptionalwaitAfterFailedPublishMs?: number
    1000
    

Instance of the database connection.

Instance of the specific database where the OutboxConsumer will work on.

A callback implemented on the client that is rensposible to publish an event.
It can utilize an event bus like RabbitMQ, Apache Pulsar or whatever is needed.
It takes an event of Event.
The most important is to throw an error on a failed publish. Otherwise, the OutboxConsumer won't consider the event as published.

Name of the partition of the OutboxConsumer.

Time after the OutboxConsumer will wait after a failed event publish.

Indicates whether the OutboxConsumer should register a cleaning callback on SIGTERM and SIGINT.

A callback fired on a failed publish.

A callback failed on an error related to the database. Event - Events handled by the OutboxConsumer. The type can be limited with a discrimitation union.

const outbox = createOutboxConsumer<Event1 | Event2>({
client,
db: client.db('hospital'),
publish: async (event) => await eventBus.publish(event),
})