java 客户端用的 curator 加了监听之后节点删除不了 修改依赖到 2.4.2 就可以 代码如下
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>4.2.0</version>
</dependency>
public static void main(String[] args) throws Exception {
CuratorFramework client = CuratorFrameworkFactory
.builder()
.connectString("192.168.215.128:2181")
.sessionTimeoutMs(5000)
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.build();
client.start();
String path = "/zk-book";
PathChildrenCache cache = new PathChildrenCache(client, path, true);
cache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
cache.getListenable().addListener((client1, event) -> {
switch (event.getType()) {
case CHILD_ADDED:
System.out.println("CHILD_ADDED," + event.getData().getPath());
break;
case CHILD_UPDATED:
System.out.println("CHILD_UPDATED," + event.getData().getPath());
break;
case CHILD_REMOVED:
System.out.println("CHILD_REMOVED," + event.getData().getPath());
break;
default:
break;
}
});
client.create()
.withMode(CreateMode.PERSISTENT)
.forPath(path);
Thread.sleep(2000);
client.delete().deletingChildrenIfNeeded().forPath(path);
System.out.println("done");
Thread.sleep(Integer.MAX_VALUE);
}