参考链接:https://my.oschina.net/u/237688/blog/808415

在项目中使用到Apache Curator Framework连接Zookeeper 3.4.9服务器,使用的Curator Framework版本是最新版3.2.1

<dependency>
	<groupId>org.apache.curator</groupId>
	<artifactId>curator-framework</artifactId>
	<version>3.2.1</version>
</dependency>

项目同时导入了zookeeper-3.5.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 3.2.1版本,不支持Zookeeper 3.4.9服务器,所以会抛出这个异常, 将Curator Framework的版本改为2.x.x的最后一个版本2.11.1,再运行程序就没有异常了。

<dependency>
	<groupId>org.apache.curator</groupId>
	<artifactId>curator-framework</artifactId>
	<version>2.11.1</version>
</dependency>

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

Logo

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

更多推荐