Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

zookeeper 的 watch 机制导致的问题 #71

Open
ccqstark opened this issue Aug 8, 2022 · 1 comment
Open

zookeeper 的 watch 机制导致的问题 #71

ccqstark opened this issue Aug 8, 2022 · 1 comment

Comments

@ccqstark
Copy link

ccqstark commented Aug 8, 2022

guide 哥我在复习 zookeeper 的时候发现它的 watcher 机制会在触发一次后就删除掉监听器,也就是说现在只能对节点的一次改变进行监听,第二次就不生效了。
目前有两种解决方案:

  1. 在回调函数里再次注册一个新的监听器
  2. 删除本地缓存的服务表,这样下一次去读取服务列表的时候就会重新去 zookeeper 拉最新数据,类似 Redis 和 MySQL 做双写一致性时的操作
PathChildrenCacheListener pathChildrenCacheListener = (curatorFramework, pathChildCacheEvent) -> {
    // List<String> serviceAddresses = curatorFramework.getChildren().forPath(servicePath);
    // SERVICE_ADDRESS_MAP.put(rpcServiceName, serviceAddresses);
    // 删除缓存以便下次从 zookeeper 拉取最新数据
    SERVICE_ADDRESS_MAP.remove(rpcServiceName);
};
@gtk123
Copy link

gtk123 commented Nov 16, 2023

CuratorFramework好像可以反复注册监听器

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants