2

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()

enter image description here

how can I get the number of partitions?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
hi im Bacon
  • 374
  • 1
  • 12

1 Answers1

3

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.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245