UNPKG

smart-saga-pattern

Version:

A library implementing the Saga pattern for microservice architecture

54 lines (53 loc) 1.5 kB
import { MessageBrokerAdapter, SagaMessage } from '../../types'; /** * Options for the RabbitMQAdapter */ export interface RabbitMQAdapterOptions { url: string; exchange: string; exchangeType?: string; } /** * Adapter for RabbitMQ message broker * Note: This is a placeholder implementation. In a real implementation, * you would use a RabbitMQ client library like 'amqplib'. */ export declare class RabbitMQAdapter implements MessageBrokerAdapter { private options; private handlers; private connected; /** * Creates a new RabbitMQAdapter * @param options RabbitMQ adapter options */ constructor(options: RabbitMQAdapterOptions); /** * Connects to RabbitMQ */ connect(): Promise<void>; /** * Disconnects from RabbitMQ */ disconnect(): Promise<void>; /** * Publishes a message to a topic * @param topic Topic to publish to * @param message Message to publish */ publish(topic: string, message: SagaMessage): Promise<void>; /** * Subscribes to a topic * @param topic Topic to subscribe to * @param handler Handler function for messages */ subscribe(topic: string, handler: (message: SagaMessage) => Promise<void>): Promise<void>; /** * Unsubscribes from a topic * @param topic Topic to unsubscribe from */ unsubscribe(topic: string): Promise<void>; /** * Ensures the adapter is connected */ private ensureConnected; }