简体   繁体   English

Zookeeper-如何在集群中获取节点崩溃事件?

[英]Zookeeper - how to get a node crash event in a cluster?

I am using Zookeeper as a group communication framework for clustering. 我将Zookeeper用作集群的群组通信框架。 In my cluster, whenever a node crashes, i want an event for the same. 在我的群集中,每当一个节点崩溃时,我都想要一个相同的事件。 How to do this ? 这个怎么做 ? Earlier i was using JGroup as the group communication framework where each of my nodes inside the cluster use to connect to the same channel and whenever a particular node crashes, Jgroup generates an event. 早些时候,我使用JGroup作为组通信框架,群集中的每个节点都用来连接到同一通道,并且每当特定节点崩溃时,Jgroup都会生成一个事件。

You can have each node create an ephemeral znode in zookeeper. 您可以让每个节点在zookeeper中创建一个临时 znode。 When a node crashes, the ephemeral znode will disappear. 当节点崩溃时,临时znode将消失。

Now to be notified of new nodes joining and leaving, have all the ephemeral znodes be a child of the same parent znode, and register a watch on the children of the parent znode. 现在要通知新节点加入和离开,让所有临时znode成为同一父znode的子节点,并在父znode的子节点上注册手表 This watch will fire when child znodes are added and removed, allowing you to see when nodes join or leave the cluster. 添加和删​​除子znode时将触发此手表,使您可以查看节点何时加入或离开集群。

Remember to re-register your watch every time it fires, and be aware that if a node joins and leaves very quickly, you may miss the event. 请记住,每次启动手表时都要重新注册手表,并请注意,如果节点加入并离开得很快,您可能会错过该事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM