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

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

问题描述

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

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 properties = new Properties();
properties.setProperty("broker.id", "1");
properties.setProperty("port", "9092");
properties.setProperty("log.dirs", "D://workspace//");
properties.setProperty("zookeeper.connect", "localhost:2181"); 

Option<String> option = Option.empty();
KafkaConfig config = new KafkaConfig(properties);       
KafkaServer kafka = new KafkaServer(config, new CurrentTime(), option);
kafka.startup();

在这种情况下 if (kafka != null) 是不够的,因为它总是正确的.那么有什么方法可以知道我的 kafka 服务器正在运行并准备好供生产者使用.我有必要检查一下,因为它会导致一些起始数据包丢失.

In this case if (kafka != 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 分配一个 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:

回声转储 |nc 本地主机 2181 |grep 经纪人

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

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

注意,以上假设:

  • 您在 localhost 上的默认端口 (2181) 上运行 ZooKeeper,并且 localhost 是集群的领导者
  • 您的 zookeeper.connect Kafka 配置没有为您的 Kafka 集群指定 chroot 环境,即它只是 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天全站免登陆