需要加入的依赖jar包
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
</dependency>
代码如下:
public static void main(String[] args) throws InterruptedException, ExecutionException {
Properties pro = new Properties();
pro.put("bootstrap.servers", "kafka地址");
//KafkaUtils.getTopicNames(zkAddress)
ListTopicsResult result = KafkaAdminClient.create(pro).listTopics();
KafkaFuture<Set<String>> set = result.names();
System.out.println(set.get());
}
执行结果: