I am creating partition for a topic dynamically using AdminUtils. I have to get the partitionId of the newly created partition for saving it in Mysql for my business logic. How can I achieve this ? My current code :
AdminUtils.addPartitions(zkUtils,KAFKA_PRODUCER_TOPIC,currentPartitionCount+1,"",true);
List<PartitionInfo> infoList = producer.partitionsFor(KAFKA_PRODUCER_TOPIC);
for(PartitionInfo info : infoList){
System.out.println(info.partition());
}
createdPartionId = infoList.get(0).partition();
Problem with above is that latest created partition is not coming in the PartitionInfo list. Don't know why.producer is the Kafka Producer API.
You can do a TopicMetadataRequest
. See the example . You can do one before and after and compare the results. Otherwise, the new partition always gets added with a newPartitionID == previousLastPartitionID + 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.