主要是在zk的/brokers/[0...N] 路径上建立该Broker的信息,并且该节点是ZK中的Ephemeral Node,当此Broker离线的时候,zk上对应的节点也就消失了,那么其它Broker可以及时发现该Broker的异常。class KafkaHealthcheck(private val brokerId: Int, private val advertisedHost: String, private val advertisedPort: Int, private val zkSessionTimeoutMs: Int, private val zkClient: ZkClient) extends Logging { val brokerIdPath = ZkUtils.BrokerIdsPath + "/" + brokerId val sessionExpireListener = new SessionExpireListener def startup() { zkClient.subscribeStateChanges(sessionExpireListener) register() } def shutdown() { zkClient.unsubscribeStateChanges(sessionExpireListener) ZkUtils.deregisterBrokerInZk(zkClient, brokerId) } def register() { val advertisedHostName = if(advertisedHost == null || advertisedHost.trim.i
kafka源码解析之十三KafkaHealthcheck
最新推荐文章于 2024-08-19 10:12:46 发布
KafkaHealthcheck类用于在Zookeeper中注册并监控Broker的状态。当Broker离线时,其在ZK上的临时节点消失,其他Broker能检测到异常。启动时,它订阅状态变化并在/brokers/ids/路径下创建Broker信息。SessionExpireListener确保短暂的ZK断连后能重新注册Broker,防止节点丢失。
摘要由CSDN通过智能技术生成