smart-saga-pattern
Version:
A library implementing the Saga pattern for microservice architecture
55 lines (54 loc) • 1.5 kB
TypeScript
import { EventPublisher } from './EventPublisher';
import { EventHandler, EventSubscriber } from './EventSubscriber';
/**
* Options for a SagaParticipant
*/
export interface SagaParticipantOptions {
name: string;
subscribeTopic: string;
publishTopic: string;
}
/**
* Represents a participant in a choreography-based Saga
*/
export declare class SagaParticipant {
private name;
private subscribeTopic;
private publishTopic;
private publisher;
private subscriber;
private handlers;
/**
* Creates a new SagaParticipant
* @param options Options for the participant
* @param publisher Event publisher
* @param subscriber Event subscriber
*/
constructor(options: SagaParticipantOptions, publisher: EventPublisher, subscriber: EventSubscriber);
/**
* Starts the participant
*/
start(): Promise<void>;
/**
* Stops the participant
*/
stop(): Promise<void>;
/**
* Registers a handler for a specific event type
* @param eventType Type of event to handle
* @param handler Handler function
*/
on(eventType: string, handler: EventHandler): void;
/**
* Publishes an event
* @param type Event type
* @param payload Event payload
* @param sagaId ID of the Saga
*/
publish(type: string, payload: any, sagaId: string): Promise<void>;
/**
* Handles an incoming event
* @param event Event to handle
*/
private handleEvent;
}