使用Apache Curator连接Zookeeper版本问题

在项目中使用到Apache Curator Framework连接zookeeper-3.4.5-cdh5.7.0,使用的Curator Framework版本是最新版4.0.1



    org.apache.curator
    curator-framework
    4.0.1

结果在使用CuratorFramework.create()方法创建新的节点时,抛出异常如下:

org.apache.zookeeper.KeeperException$UnimplementedException: 
KeeperErrorCode = Unimplemented for [zk节点路径名]

开始我以为是我设置的zk节点路径不正确,结果加上了/zookeeper父路径后,抛出同样的异常,google了一下才知道,Curator Framework的2.x.x版本和3.x.x版本对Zookeeper支持的版本是有差异的,查看Curator Framework的官网(http://curator.apache.org),在Versions部分有这么一段话:

Versions
The are currently two released versions of Curator, 2.x.x and 3.x.x:

Curator 2.x.x - compatible with both ZooKeeper 3.4.x and ZooKeeper 3.5.x
Curator 3.x.x - compatible only with ZooKeeper 3.5.x and includes support for new features such as dynamic reconfiguration, etc.

对于zookeeper 3.4.x服务器版本,只有Curator 2.x.x才支持,我使用的是Curator 4.0.1版本,不支持Zookeeper 3.4.5,所以会抛出这个异常, 将Curator Framework的版本改为2.x.x的最后一个版本2.11.1,再运行程序就没有异常了。


	org.apache.curator
	curator-framework
	2.11.1

大家在直接使用Curator Framework进行Zk监控,或者使用Spring Cloud Zookeeper Config时(内含Curator Framework的引用),请注意连接的zookeeper服务器版本,根据zk服务器版本的不同,选择不同的Curator Framework版本。

你可能感兴趣的:(zookeeper)