简体   繁体   English

通过Java API获取ZooKeeper服务器版本

[英]Getting ZooKeeper server version via Java API

I'm finding that some Apache Curator recipes don't work with older versions of ZooKeeper. 我发现某些Apache Curator食谱不适用于较旧版本的ZooKeeper。 This isn't an issue except that I keep having developers in my company try to use some code I wrote and it fails without any errors or log messages due to them running an old version of their local machine. 这不是问题,除了我一直在公司中让开发人员尝试使用我编写的某些代码,并且由于他们运行的是本地计算机的旧版本而失败时,没有任何错误或日志消息。 So I want to retrive the version of the ZooKeeper server to which I'm connected and die with an useful error message if the version is too old. 因此,我想检索我连接到的ZooKeeper服务器的版本,如果版本太旧,则会显示一条有用的错误消息,以使其消失。 However, I can't find any way to get the server's version number with either the Curator or ZooKeeper APIs. 但是,我找不到使用Curator或ZooKeeper API获取服务器版本号的任何方法。 Anyone know how to do it? 有人知道怎么做吗?

The ZooKeeper "four letter words" can help. ZooKeeper的“四个字母单词”可以提供帮助。 You can connect to the local ZK instance on port 2181 and execute a "srvr" four letter word. 您可以在端口2181上连接到本地ZK实例,并执行“ srvr”四个字母的单词。 You'll get back lines of info one of which is the version. 您将获得信息行,其中之一是版本。

Have a look at Exhibitor's FourLetterWord class for a sample of how to get this programmatically: https://github.com/Netflix/exhibitor/blob/40a02452dc3133fe37bf4ecf076bda99c29ab6ec/exhibitor-core/src/main/java/com/netflix/exhibitor/core/state/FourLetterWord.java 请查看参展商的FourLetterWord类,以获取如何以编程方式获取此示例的示例: https : //github.com/Netflix/exhibitor/blob/40a02452dc3133fe37bf4ecf076bda99c29ab6ec/exhibitor-core/src/main/java/com/netflix/exhibitor/core /state/FourLetterWord.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM