Kind: Interface
Source: packages/microservices/external/kafka.interface.ts
Part of: Microservices
TopicOffsets represents Kafka offset information for a single topic across one or more partitions. It is typically used when committing offsets, seeking to a position, or reporting consumer progress within the microservices Kafka integration.
Properties
| Property | Type |
|---|---|
topic | string |
partitions | PartitionOffset[] |
Diagram
mermaidgraph LR T[TopicOffsets] --> Topic[topic: string] T --> Partitions[partitions: PartitionOffset[]] Partitions --> P1[Partition offset] Partitions --> P2[Partition offset]
Usage
tsimport type { TopicOffsets } from './kafka.interface';
const offsets: TopicOffsets = {
topic: 'orders.created',
partitions: [
{ partition: 0, offset: '125' },
{ partition: 1, offset: '98' },
],
};
// Example: pass topic partition offsets to a Kafka consumer operation.
await consumer.commitOffsets(offsets.partitions);
AI Coding Instructions
- Provide a valid Kafka topic name in
topicand include offsets only for partitions belonging to that topic. - Use the
PartitionOffsetshape expected by the Kafka client; offsets are commonly represented as strings to preserve large integer values. - Keep partition offsets grouped under one
TopicOffsetsobject when handling topic-level consumer state. - Validate partition numbers and offsets before committing or seeking, especially when offsets originate from external storage.
- When integrating with consumer APIs, check whether the API expects
PartitionOffset[]directly or a topic-aware wrapper such asTopicOffsets.
How it works
TopicOffsets is an exported TypeScript interface that groups offset entries under one Kafka topic. It declares two required fields: topic, a string, and partitions, an array of PartitionOffset objects. [packages/microservices/external/kafka.interface.ts:776-779]
Each PartitionOffset requires a numeric partition and a string offset; therefore, every entry in partitions identifies one partition and its offset as a string. [packages/microservices/external/kafka.interface.ts:771-774]
The surrounding file declares types intended to represent the KafkaJS package rather than NestJS logic. [packages/microservices/external/kafka.interface.ts:1-8] TopicOffsets has no implementation, validation, error declaration, or direct side effect in this file. [packages/microservices/external/kafka.interface.ts:776-779]
It appears in several Kafka-facing type signatures:
Cluster.fetchTopicsOffset(...)resolves toPromise<TopicOffsets[]>. [packages/microservices/external/kafka.interface.ts:221-230]Broker.offsetCommit(...)acceptstopics: TopicOffsets[]. [packages/microservices/external/kafka.interface.ts:674-680]Broker.offsetFetch(...)acceptstopics: TopicOffsets[]and returnsresponses: TopicOffsets[]. [packages/microservices/external/kafka.interface.ts:681-683]- The consumer commit-offset instrumentation payload contains
topics: TopicOffsets[]. [packages/microservices/external/kafka.interface.ts:928-938] OffsetsandOffsetsByTopicPartitioneach wrap atopics: TopicOffsets[]array;EachBatchPayload.commitOffsetsIfNecessaryaccepts an optionalOffsets, anduncommittedOffsetsreturnsOffsetsByTopicPartition. [packages/microservices/external/kafka.interface.ts:781-783] [packages/microservices/external/kafka.interface.ts:990-1008]
Was this page helpful?