Hermes PostgreSQL
    Preparing search index...

    Type Alias ConsumerCreationParams<Message>Template

    Configuration parameters for creating an outbox consumer.

    Message - The type of domain messages/events this consumer will handle

    const params: ConsumerCreationParams<DomainEvent> = {
    getOptions: () => ({
    host: 'localhost',
    port: 5432,
    database: 'mydb',
    user: 'user',
    password: 'pass'
    }),
    publish: async (envelope) => {
    await messageBroker.publish(envelope.message)
    },
    consumerName: 'my-service'
    }
    type ConsumerCreationParams<Message extends JSONValue> = {
        asyncOutbox?: UseAsyncOutboxPolicy<Message>;
        consumerName: string;
        getOptions: () => Options<Record<string, PostgresType>>;
        maxQueueSize?: number;
        now?: NowFunction;
        onDbError?: ErrorCallback;
        onFailedPublish?: ErrorCallback;
        partitionKey?: string;
        publish: (
            message:
                | HermesMessageEnvelope<Message>
                | HermesMessageEnvelope<Message>[],
        ) => AsyncOrSync<void> | never;
        saveTimestamps?: boolean;
        serialization?: boolean;
        shouldDisposeOnSigterm?: boolean;
        waitAfterFailedPublish?: Duration;
    }

    Type Parameters

    Index

    Policy for configuring a separate async outbox consumer.

    The async outbox is used for non-critical messages like compensations.

    consumerName: string

    Unique name for this consumer instance.

    Used to create a PostgreSQL replication slot.

    getOptions: () => Options<Record<string, PostgresType>>

    Function that returns PostgreSQL connection options.

    Type Declaration

      • (): Options<Record<string, PostgresType>>
      • Returns Options<Record<string, PostgresType>>

        Postgres.js connection options

    maxQueueSize?: number

    Maximum number of transactions waiting to be published or acknowledged.

    When the limit is reached, Hermes stops reading the replication stream, so PostgreSQL holds the changes in the WAL instead of the consumer holding them in memory. Reading resumes once the queue drops to half the limit. With serialization: false, it also caps the number of concurrent publish calls.

    1000

    Function that returns the current date/time.

    Current date/time

    () => new Date()

    onDbError?: ErrorCallback

    Callback invoked when a database error occurs.

    The database error

    No-op function
    
    onFailedPublish?: ErrorCallback

    Callback invoked when message publishing fails.

    The error that occurred

    No-op function
    
    partitionKey?: string

    Partition key for horizontal scaling.

    'default'

    publish: (
        message:
            | HermesMessageEnvelope<Message>
            | HermesMessageEnvelope<Message>[],
    ) => AsyncOrSync<void> | never

    Callback invoked when Hermes delivers a message.

    If this callback completes successfully, the message is acknowledged. If it throws an error, the message will be retried.

    Type Declaration

    Error to trigger redelivery

    saveTimestamps?: boolean

    Whether to save processing timestamps for each message.

    ⚠️ Use with caution: Significantly increases I/O operations.

    false

    serialization?: boolean

    Whether to process messages serially (one at a time) or concurrently.

    false

    shouldDisposeOnSigterm?: boolean

    Whether to automatically stop the consumer on SIGTERM/SIGINT signals.

    true

    waitAfterFailedPublish?: Duration

    Duration to wait after a failed publish attempt before retrying.

    Duration.ofSeconds(30)