V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zuicaidenage
V2EX  ›  Java

zookeeper 的节点删除不了?

  •  
  •   zuicaidenage · 2019-09-04 18:33:19 +08:00 · 3800 次点击
    这是一个创建于 1940 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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);
        }
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1020 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 22:28 · PVG 06:28 · LAX 14:28 · JFK 17:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.