UNPKG

smart-saga-pattern

Version:

A library implementing the Saga pattern for microservice architecture

58 lines (57 loc) 1.58 kB
import { MessageBrokerAdapter, SagaMessage } from "../../types"; /** * Options for the RedisAdapter */ export interface RedisAdapterOptions { url: string; prefix?: string; } /** * Adapter for Redis Pub/Sub * Note: This is a placeholder implementation. In a real implementation, * you would use a Redis client library like 'ioredis'. */ export declare class RedisAdapter implements MessageBrokerAdapter { private options; private handlers; private connected; /** * Creates a new RedisAdapter * @param options Redis adapter options */ constructor(options: RedisAdapterOptions); /** * Connects to Redis */ connect(): Promise<void>; /** * Disconnects from Redis */ disconnect(): Promise<void>; /** * Publishes a message to a channel * @param topic Channel to publish to * @param message Message to publish */ publish(topic: string, message: SagaMessage): Promise<void>; /** * Subscribes to a channel * @param topic Channel to subscribe to * @param handler Handler function for messages */ subscribe(topic: string, handler: (message: SagaMessage) => Promise<void>): Promise<void>; /** * Unsubscribes from a channel * @param topic Channel to unsubscribe from */ unsubscribe(topic: string): Promise<void>; /** * Gets the full channel name with prefix * @param topic Base topic name */ private getChannelName; /** * Ensures the adapter is connected */ private ensureConnected; }