How can I get number of partitions for any kafka topic from the code. I have researched many links but none seem to work.
Mentioning a few:
http://grokbase.c
Use PartitionList from KafkaConsumer
//create consumer then loop through topics
KafkaConsumer consumer = new KafkaConsumer(props);
List partitions = consumer.partitionsFor(topic);
ArrayList partitionList = new ArrayList<>();
System.out.println(partitions.get(0).partition());
for(int i = 0; i < partitions.size(); i++){
partitionList.add(partitions.get(i).partition());
}
Collections.sort(partitionList);
Should work like a charm. Let me know if there's a simpler way to access Partition List from Topic.