有什么方法可以检查 kafka 是否已从 kafka-net 启动并运行 [英] Is there any way to check if kafka is up and running from kafka-net
问题描述
我正在使用 kafka-net 客户端向 kafka 发送消息.我只是想知道是否有任何方法可以检查 kafka 服务器是否已启动并可以接收消息.我关闭了 kafka,但是已经成功创建了生产者并且 SendMessageAsync 只是冻结了很长时间.我试图通过超时,但它没有改变任何东西.我使用 kafka-net 0.9当 kafka 服务器启动并运行时它工作得很好
I am using kafka-net client to send messages to kafka. I'm just wondering if there is any way to check is kafka server up and can receive messages. I shut kafka down, but the producer has been created successfully and SendMessageAsync just freezes for quite a long time. I've tried to pass timeout but it doesn't change anything. I use kafka-net 0.9 It works just fine when kafka server is up and running
推荐答案
Broker 的 id 在 zookeeper(/brokers/ids/[brokerId]
) 中注册为临时节点,允许其他 Broker 和消费者检测故障.(现在健康的定义还很幼稚.如果在 zk /brokers/ids/[brokerId]
中注册,broker 是健康的,否则它就死了).
Broker's id is registered in zookeeper(/brokers/ids/[brokerId]
) as ephemeral node, which allow other brokers and consumers to detect failures.(Right now the definition of health is fairly naive., if registered in zk /brokers/ids/[brokerId]
the broker is healthy, otherwise it is dead).
zookeeper 临时节点存在,只要代理的会话是活跃.
zookeeper ephemeral node exists as long as the broker's session is active.
您可以通过 ZkUtils.getSortedBrokerList(zkClient) 检查代理是否已启动,它返回 /brokers/ids
You could check if broker is up via ZkUtils.getSortedBrokerList(zkClient), which return all active broker id under /brokers/ids
import org.I0Itec.zkclient.ZkClient;
ZkClient zkClient = new ZkClient(properties.getProperty("zkQuorum"), zkSessionTimeout, zkConnectionTimeout,ZKStringSerializer$.MODULE$);
ZkUtils.getSortedBrokerList(zkClient);
这篇关于有什么方法可以检查 kafka 是否已从 kafka-net 启动并运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!