简体   繁体   中英

How can we get Replication Factor and Retention Hours of the Topic using Apache Kafka API

How can we get Replication Factor and Retention Hours of the Topic using Apache Kafka API?

I am using version 0.9 and figured how to use AdminUtils to get number of paritiions.

If you are already familiar with the the AdminUtils it's not that far to go. Get the config of the topic you are interest in. You'll get a map with all configuration items of this topic. At least in kafka 0.8.x the key for the retention configuration was "retention.ms". So let's try this one (Disclaimer - This is unchecked code):

val zkUtils = ZkUtils(zkConnectionString,
                      30000,
                      30000,
                      JaasUtils.isZkSecurityEnabled())
val configs = AdminUtils.fetchEntityConfig(zkUtils, ConfigType.Topic, topicName)
val retention = configs("retention.ms")

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM