如何检查Kafka Server是否正在运行? [英] How to check whether Kafka Server is running?

查看:5612
本文介绍了如何检查Kafka Server是否正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在开始生产和消费工作之前确保kafka服务器是否正在运行。它是在windows环境中,这是我的kafka服务器在eclipse中的代码...

I want to ensure whether kafka server is running or not before starting production and consumption jobs. It is in windows environment and here's my kafka server's code in eclipse...

Properties kafka = new Properties();
kafka.setProperty("broker.id", "1");
kafka.setProperty("port", "9092");
kafka.setProperty("log.dirs", "D://workspace//");
kafka.setProperty("zookeeper.connect", "localhost:2181");    
Option<String> option = Option.empty();
KafkaConfig config = new KafkaConfig(kafka);        
KafkaServer server = new KafkaServer(config, new CurrentTime(), option);
server.startup();

在这种情况下 if(server!= null)还不够,因为它总是如此。那么有没有办法知道我的kafka服务器正在运行并为生产者做好准备。我有必要检查一下,因为它会导致丢失一些起始数据包。

In this case if (server != null) is not enough because it is always true. So is there any way to know that my kafka server is running and ready for producer. It is necessary for me to check this because it causes loss of some starting data packets.

谢谢。

推荐答案

必须为所有Kafka经纪人分配 broker.id 。启动时,代理将在Zookeeper中创建一个短暂的节点,路径为 / broker / ids / $ id 。由于节点是短暂的,所以一旦代理断开连接,它将被移除,例如,通过关闭。

All Kafka brokers must be assigned a broker.id. On startup a broker will create an ephemeral node in Zookeeper with a path of /broker/ids/$id. As the node is ephemeral it will be removed as soon as the broker disconnects, e.g. by shutting down.

您可以查看短暂的代理节点列表,如下所示:

You can view the list of the ephemeral broker nodes like so:

echo dump | nc localhost 2181 | grep brokers

ZooKeeper客户端接口公开了许多命令; dump 列出集群的所有会话和临时节点。

The ZooKeeper client interface exposes a number of commands; dump lists all the sessions and ephemeral nodes for the cluster.

注意,上面假设:


  • 您在上的默认端口( 2181 )上运行ZooKeeper localhost ,而 localhost 是群集的领导者

  • 您的 zookeeper .connect Kafka config没有为你的Kafka集群指定一个chroot env,即它只是 host:port 而不是 host :port / path

  • You're running ZooKeeper on the default port (2181) on localhost, and that localhost is the leader for the cluster
  • Your zookeeper.connect Kafka config doesn't specify a chroot env for your Kafka cluster i.e. it's just host:port and not host:port/path

这篇关于如何检查Kafka Server是否正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆