客户端应用程序使用Kafka主要分为两种类型,即生产者和消费者。无论哪种都需要kafka服务处于运行状态,本文介绍几种方法检查kafka服务器的运行状态。
$ echo dump | nc localhost 2181 | grep -i broker | xargs
/brokers/ids/0
lw.commands.whitelist=dump
public class KafkaAdminClient {
private final AdminClient client;
public KafkaAdminClient(String bootstrap) {
Properties props = new Properties();
props.put("bootstrap.servers", bootstrap);
props.put("request.timeout.ms", 3000);
props.put("connections.max.idle.ms", 5000);
this.client = AdminClient.create(props);
}
}
public boolean verifyConnection() throws ExecutionException, InterruptedException {
Collection<Node> nodes = this.client.describeCluster()
.nodes()
.get();
return nodes != null && nodes.size() > 0;
}
@Test
void givenKafkaIsRunning_whenCheckedForConnection_thenConnectionIsVerified() throws Exception {
boolean alive = kafkaAdminClient.verifyConnection();
assertThat(alive).isTrue();
}
sudo apt-get update
sudo apt-get install kafkacat
kafkacat -b localhost:29092 -t demo-topic -L
Metadata for demo-topic (from broker -1: localhost:29092/bootstrap):
3 brokers:
broker 2 at localhost:29092
broker 3 at localhost:39092
broker 1 at localhost:19092
1 topics:
topic "demo-topic" with 0 partitions: Broker: Leader not available (try again)
免责申明:
本文系转载,版权归原作者所有,如若侵权请联系我们进行删除!
《数据治理行业实践白皮书》下载地址:https://fs80.cn/4w2atu
《数栈V6.0产品白皮书》下载地址:https://fs80.cn/cw0iw1
想了解或咨询更多有关袋鼠云大数据产品、行业解决方案、客户案例的朋友,浏览袋鼠云官网:https://www.dtstack.com/?src=bbs
同时,欢迎对大数据开源项目有兴趣的同学加入「袋鼠云开源框架钉钉技术群」,交流最新开源技术信息,群号码:30537511,项目地址:https://github.com/DTStack