Kind: Interface
Source: packages/microservices/external/kafka.interface.ts
Part of: Microservices
OffsetsByTopicPartition groups Kafka offset information by topic and partition. It is used when reading, committing, or reporting consumer positions across one or more Kafka topics in the microservices Kafka integration.
Properties
| Property | Type |
|---|---|
topics | TopicOffsets[] |
Diagram
mermaidgraph LR A[OffsetsByTopicPartition] --> B[topics: TopicOffsets[]] B --> C[Topic offset entry] C --> D[Kafka topic] C --> E[Partition offsets]
Usage
tsimport type { OffsetsByTopicPartition } from './kafka.interface';
const offsets: OffsetsByTopicPartition = {
topics: [
{
topic: 'orders',
partitions: [
{ partition: 0, offset: '142' },
{ partition: 1, offset: '98' },
],
},
{
topic: 'payments',
partitions: [{ partition: 0, offset: '51' }],
},
],
};
// Pass the grouped offsets to Kafka consumer offset handling logic.
await consumer.commitOffsets(offsets.topics.flatMap((topic) => topic.partitions));
AI Coding Instructions
- Populate
topicswithTopicOffsetsentries; do not place partition offsets directly onOffsetsByTopicPartition. - Preserve Kafka offsets as strings when required by the underlying client to avoid JavaScript integer precision issues.
- Group offsets by their Kafka topic before constructing this interface.
- Validate that each partition belongs to the topic named by its corresponding
TopicOffsetsentry. - Use this type at Kafka consumer integration boundaries for offset commit, seek, or lag-reporting workflows.
Was this page helpful?