需要加入的依赖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());
}
执行结果:
版权声明:本文为cjj386906718原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。