Kind: Interface
Source: packages/microservices/external/kafka.interface.ts
Part of: Microservices
ITopicPartitionConfig defines Kafka topic partitioning configuration for microservice deployments. It specifies the topic name, total partition count, and optional explicit replica assignments used when creating or configuring Kafka topics.
Properties
| Property | Type |
|---|---|
topic | string |
count | number |
assignments | Array<Array<number>> |
Diagram
mermaidgraph LR Config[ITopicPartitionConfig] Config --> Topic[topic: string] Config --> Count[count: number] Config --> Assignments[assignments: number[][]] Assignments --> Partition0[Partition replica broker IDs] Assignments --> PartitionN[Additional partition replica broker IDs]
Usage
tsimport type { ITopicPartitionConfig } from './kafka.interface';
const ordersTopicConfig: ITopicPartitionConfig = {
topic: 'orders.created',
count: 3,
assignments: [
[1, 2, 3],
[2, 3, 1],
[3, 1, 2],
],
};
// Pass the configuration to the Kafka topic provisioning layer.
await kafkaAdmin.createTopics({
topics: [
{
topic: ordersTopicConfig.topic,
numPartitions: ordersTopicConfig.count,
replicaAssignment: ordersTopicConfig.assignments,
},
],
});
AI Coding Instructions
- Keep
countaligned with the number of entries inassignmentswhen explicit assignments are provided. - Represent each partition assignment as an array of Kafka broker IDs; ordering typically determines the preferred replica leader.
- Use a unique, stable Kafka topic name in
topic, following the project's topic naming conventions. - Validate that every broker ID in
assignmentsexists in the target Kafka cluster before provisioning. - Integrate this interface with Kafka admin/topic-creation code rather than consumer or producer runtime configuration.
Was this page helpful?