UNPKG

kafka-ts

Version:

**KafkaTS** is a Apache Kafka client library for Node.js. It provides both a low-level API for communicating directly with the Apache Kafka cluster and high-level APIs for publishing and subscribing to Kafka topics.

34 lines (33 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProducerState = void 0; const api_1 = require("../api"); class ProducerState { options; producerId = 0n; producerEpoch = 0; sequences = {}; constructor(options) { this.options = options; } async initProducerId() { const result = await this.options.cluster.sendRequest(api_1.API.INIT_PRODUCER_ID, { transactionalId: null, transactionTimeoutMs: 0, producerId: this.producerId, producerEpoch: this.producerEpoch, }); this.producerId = result.producerId; this.producerEpoch = result.producerEpoch; this.sequences = {}; } getSequence(topic, partition) { return this.sequences[topic]?.[partition] ?? 0; } updateSequence(topic, partition, messagesCount) { this.sequences[topic] ??= {}; this.sequences[topic][partition] ??= 0; this.sequences[topic][partition] += messagesCount; } } exports.ProducerState = ProducerState;