UNPKG

@axinom/mosaic-transactional-inbox-outbox

Version:

This library encapsulates the Mosaic based transactional inbox and outbox pattern

59 lines 2.72 kB
import { MessageHandler, MessageInfo } from '@axinom/mosaic-message-bus'; import { MessagingSettings } from '@axinom/mosaic-message-bus-abstractions'; import { Pool } from 'pg'; import { Dict, InboxOutboxLogger } from '../common'; import { OptionalInboxData, StoreInboxMessage } from './setup-inbox-storage'; export interface InboxMessageInput extends OptionalInboxData { messageId: string; aggregateId: string; messagingSettings: Pick<MessagingSettings, 'messageType' | 'aggregateType'>; payload: unknown; } export interface CustomMessageMapper { (message: MessageInfo): InboxMessageInput | undefined; } export interface CustomMessagePreProcessor { (message: InboxMessageInput): void; } export interface InboxWriterCustomizations { /** * A custom message mapper for messages that do not follow the Mosaic messaging * pattern. Returns either an TransactionalMessage or undefined - in this case * the default mapping is used. */ customMessageMapper?: CustomMessageMapper; /** * A custom message processor to change message properties before storing the * inbox message. This can be useful to define the segment or the concurrency * processing. */ customMessagePreProcessor?: CustomMessagePreProcessor; /** * An optional list of all messages that are expected for backward compatibility. * Old clients may not send in the aggregate type yet so this will provide a * mapping to find the aggregate type by the event type only. */ acceptedMessageSettings?: MessagingSettings[]; } export declare class RabbitMqInboxWriter extends MessageHandler<unknown> { protected storeInboxMessage: StoreInboxMessage; protected ownerPool: Pool; protected logger: InboxOutboxLogger; private customMessageMapper?; private customMessagePreProcessor?; private backwardCompatibilityMappings; private mutex; /** * Creates a new RabbitMQ-based handler that receives all events and commands * and stores them in the transactional inbox. * @param storeInboxMessage Function to store the incoming RabbitMQ message in the transactional inbox * @param customizations Provide custom logic on how the inbox writer should process messages */ constructor(storeInboxMessage: StoreInboxMessage, ownerPool: Pool, logger: InboxOutboxLogger, customizations?: InboxWriterCustomizations); backwardCompatibilityMapper: (acceptedMessageSettings?: MessagingSettings[]) => Dict<string>; /** * Store the incoming message in the transactional inbox. */ onMessage(payload: unknown, message: MessageInfo<unknown>): Promise<void>; } //# sourceMappingURL=rabbitmq-inbox-writer.d.ts.map