UNPKG

pegasys-orchestrate

Version:

The PegaSys Orchestrate library provides convenient access to the Codefi Orchestrate API from applications written in server-side JavaScript

47 lines (46 loc) 1.5 kB
import * as KafkaJS from 'kafkajs'; import { KafkaClient } from '../KafkaClient'; import { IResponse } from '../types'; /** * Consumes and decodes Orchestrate messages */ export declare class Consumer extends KafkaClient { private readonly consumer; private readonly topics; /** * Creates a new instance of the Consumer * * @param brokers - List of brokers to connect to * @param topics - List of topics to consume * @param kafkaConfig - Kafka client configuration * @param consumerConfig - Consumer configuration */ constructor(brokers: string[], topics?: string[], kafkaConfig?: Omit<KafkaJS.KafkaConfig, 'brokers'>, consumerConfig?: KafkaJS.ConsumerConfig); /** * Returns the list of topics */ getTopics(): string[]; /** * Connects to Kafka and subscribes to each topic * * @returns a Promise that resolves if the connection is successful and rejects otherwise */ connect(): Promise<void>; /** * Disconnects from the broker and unsubscribes from the topics * * @returns a Promise that resolves if the connection is disconnected successfully */ disconnect(): Promise<void>; /** * Starts consuming messages */ consume(): Promise<void>; /** * Commits the offsets specified by the message * * @param message - Message from which to get the offset */ commit(message: IResponse): Promise<void>; private checkReadiness; }