ZooKeeper 开发随笔

Dubbo 使用 Curator 连接 ZooKeeper 失败

异常日志:

1
Caused by: org.apache.zookeeper.KeeperException$UnimplementedException: KeeperErrorCode = Unimplemented for /dubbo/xxx.xxx.service.UserService/providers/dubbo ....

异常分析:ZooKeeper 的版本与 Curator 的版本不兼容所导致,Curator 官网说明如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
第一种情况:

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.5.x
Curator 4.0 has a hard dependency on ZooKeeper 3.5.x
If you are using ZooKeeper 3.5.x there's nothing additional to do - just use Curator 4.0

ZooKeeper 3.4.x
Curator 4.0 supports ZooKeeper 3.4.x ensembles in a soft-compatibility mode. To use this mode you must exclude ZooKeeper when adding Curator to your dependency management tool.

解决方法:针对第二种情况,假设各组件的版本分别为 Dubbo (2.7.0)、ZooKeeper (3.4.13)、Curator-Framework (4.0.1),则需要排除 Curator-Framework (4.0.1) 默认依赖的高版本 ZooKeeper (3.5.x),然后指定低版本的 ZooKeeper (3.4.x),Maven 的 POM 写法如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<dependencies>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.13</version>
</dependency>

<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.0.1</version>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>