How to get topic list from kafka server in Java

后端 未结 6 539

I am using kafka 0.8 version and very much new to it.

I want to know the list of topics created in kafka server along with it\'s metadata.

6条回答
  •  醉话见心
    2020-12-29 07:15

    You can use zookeeper API to get the list of brokers as mentioned below:

        ZooKeeper zk = new ZooKeeper("zookeeperhost, 10000, null);
        List ids = zk.getChildren("/brokers/ids", false);
        List brokerList = new ArrayList<>();
        ObjectMapper objectMapper = new ObjectMapper();
    
        for (String id : ids) {
            Map map = objectMapper.readValue(zk.getData("/brokers/ids/" + id, false, null), Map.class);
            brokerList.add(map);
        }
    

    Use this broker list to get all the topic using the following link

    https://cwiki.apache.org/confluence/display/KAFKA/Finding+Topic+and+Partition+Leader

提交回复
热议问题