'Confluent kafka python API - how to get number of partitions in a topic
I would like to get the number of partitions within a topic but the API is difficult to understand at best.
I found the following, but, the topic information doesn't contain the numbers of partitions.
import confluent_kafka
from confluent_kafka.admin import AdminClient, ConfigResource
kafkaServers = ["***","****"]
bootstrapServers = ",".join(kafkaServers)
adminClient = AdminClient({
'bootstrap.servers': bootstrapServers
})
result = adminClient.describe_configs([ConfigResource(confluent_kafka.admin.RESOURCE_TOPIC, "model-detections-dev")])
config = list(result.values())[0].result()
how can I get the number of partitions?
Solution 1:[1]
Partitions are not a "topic config" to be gotten from the AdminClient.
You can use a Consumer instance to get them
consumer.list_topics() returns ClusterMetadata, which holds a map of topics to TopicMetadata, which has a partitions attribute.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | OneCricketeer |

