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();
}
}java读取zookeeper中的配置文件信息
最新推荐文章于 2021-10-13 15:12:57 发布
本文提供了一个使用Java实现的ZooKeeper客户端示例代码,展示了如何连接ZooKeeper服务器、获取子节点列表以及读取节点数据的过程。通过此示例,读者可以了解ZooKeeper的基本操作和监听器的使用。
532

被折叠的 条评论
为什么被折叠?



