public static void main(String[] args) {
	        String connectString = "127.0.0.1:2181";
	        int sessionTimeout = 4000;
	        Watcher watcher = new Watcher() {
	            public void process(WatchedEvent event) {
	                //System.out.println(event.getPath());
	            }
	        };


	        try {
	            ZooKeeper zooKeeper = new ZooKeeper(connectString, sessionTimeout, watcher);
	            List<String> list = zooKeeper.getChildren("/config", false);
	            for (String path : list) {
	                System.out.println(path);
	                byte[] b = zooKeeper.getData("/config/"+path, false, null) ;
	                System.out.println( new String(b) );
	            }
	        } catch (IOException e) {
	            e.printStackTrace();
	        } catch (KeeperException e) {
	            e.printStackTrace();
	        } catch (InterruptedException e) {
	            e.printStackTrace();
	        }
	    }

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐