UNPKG

pg-transactional-outbox

Version:

A PostgreSQL based transactional outbox and inbox pattern implementation to support exactly once message processing (with at least once message delivery).

24 lines 1.84 kB
import { DatabaseClient } from '../common/database'; import { ListenerConfig } from '../common/listener-config'; import { StoredTransactionalMessage } from './transactional-message'; /** * This function increases the "started_attempts" for the outbox or inbox * message by one in the table. This number can then be compared to the * "finished_attempts" number which is only increased when a message processing * exception was correctly handled or an error was caught. A difference between * the two can only happen if the service crashes after increasing the * "started_attempts" but before successfully marking the message as done * (success case) or catching an error (error case). If the "started_attempts" * and the "finished_attempts" field differ by more than one, the chances are * high that this message is causing a service crash. * It sets the started_attempts, finished_attempts, locked_until. abandoned_at, * and processed_at values on the message. * For additional safety it makes sure, that the message was not and is not * currently being worked on. * @param message The message for which to acquire a lock and increment the started_attempts * @param client The database client. Must be part of a transaction that runs before the message handling transaction. * @param config The configuration settings that defines the database schema. * @returns 'MESSAGE_NOT_FOUND' if the message was not found, 'ALREADY_PROCESSED' if it was processed, and otherwise assigns the properties to the message and returns true. */ export declare const startedAttemptsIncrement: (message: StoredTransactionalMessage, client: DatabaseClient, { settings }: Pick<ListenerConfig, "settings">) => Promise<true | "MESSAGE_NOT_FOUND" | "ALREADY_PROCESSED" | "ABANDONED_MESSAGE">; //# sourceMappingURL=started-attempts-increment.d.ts.map