smart-saga-pattern
Version:
A library implementing the Saga pattern for microservice architecture
54 lines (53 loc) • 1.47 kB
TypeScript
import { MessageBrokerAdapter, SagaMessage } from '../../types';
/**
* Options for the KafkaAdapter
*/
export interface KafkaAdapterOptions {
brokers: string[];
clientId: string;
groupId: string;
}
/**
* Adapter for Kafka message broker
* Note: This is a placeholder implementation. In a real implementation,
* you would use a Kafka client library like 'kafkajs'.
*/
export declare class KafkaAdapter implements MessageBrokerAdapter {
private options;
private handlers;
private connected;
/**
* Creates a new KafkaAdapter
* @param options Kafka adapter options
*/
constructor(options: KafkaAdapterOptions);
/**
* Connects to Kafka
*/
connect(): Promise<void>;
/**
* Disconnects from Kafka
*/
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;
}