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).

33 lines 2.25 kB
import { EventEmitter } from 'events'; import { Pgoutput } from 'pg-logical-replication'; import { ExtendedError } from '../common/error'; import { TransactionalLogger } from '../common/logger'; import { StoredTransactionalMessage } from '../message/transactional-message'; import { FullReplicationListenerConfig } from './config'; import { ReplicationStrategies } from './replication-strategies'; /** * Initiate the outbox or inbox listener to listen for WAL messages. * @param config The replication connection settings and general replication settings * @param messageHandler The message handler that handles the outbox/inbox message * @param errorHandler A handler that can decide if the WAL message should be acknowledged (permanent_error) or not (transient_error which restarts the logical replication listener) * @param logger A logger instance for logging trace up to error logs * @param strategies Strategies to provide custom logic for handling specific scenarios * @returns A function to stop the logical replication listener */ export declare const createLogicalReplicationListener: (config: FullReplicationListenerConfig, messageHandler: (message: StoredTransactionalMessage, cancellation: EventEmitter) => Promise<void>, errorHandler: (message: StoredTransactionalMessage, err: ExtendedError) => Promise<boolean>, logger: TransactionalLogger, strategies: ReplicationStrategies) => [shutdown: { (): Promise<void>; }]; /** Get and map the outbox/inbox message if the WAL log entry is such a message. Otherwise returns undefined. */ declare const getRelevantMessage: (log: Pgoutput.Message, { dbSchema, dbTable }: FullReplicationListenerConfig["settings"]) => StoredTransactionalMessage | undefined; /** Maps the WAL log entry to an outbox or inbox message */ declare const mapMessage: (input: unknown) => StoredTransactionalMessage | undefined; /** * This export is _only_ done for unit tests as the createLogicalReplicationListener * function is otherwise very hard to unit test. Exports work only for jest tests! */ export declare const __only_for_unit_tests__: { getRelevantMessage?: typeof getRelevantMessage; mapMessage?: typeof mapMessage; }; export {}; //# sourceMappingURL=logical-replication-listener.d.ts.map