kafka 版本:2.1.0
具体更多的明细API用法见官网:kafka官网API
pom信息:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
<version>2.1.0</version>
</dependency>
<!-- kafka Producer&Consumer API -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.1.0</version>
</dependency>
连接初始化:
private static final String topicName = "test";
private static final String broker = "host:port";
public static AdminClient client;
static void initClient() {
if (client != null) {
client.close();
client = null;
}
try {
Properties admainProp = new Properties();
admainProp.put("bootstrap.servers", broker);
client = AdminClient.create(admainProp);
System.out.println("初始化KAFKA-Client成功!");
} catch (Exception e) {
System.out.println("初始化Client失败!");
}
}
查询Topic信息:
public void getTopicInfo(String topicName) {
DescribeTopicsResult topicsResult