最近开发的项目中需要连接到zookeeper中并注册一个节点,在应用启动后报错:
EndOfStreamException: Unable to read additional data from server sessionid 0x1772bfba8c512ee, likely server has closed socket
at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:75)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:348)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1262)
网上找寻答案,基本都是说配置问题、防火墙问题等:
https://stackoverflow.com/questions/13316776/zookeeper-connection-error/47700307#47700307
不得要领,找公司同事求助,说是zookeeper版本不一致造成的
客户端java版本是:org.apache.zookeeper:zookeeper:3.6.3
服务器的版本是:3.4.9
去官网查找相关说明:
http://curator.apache.org/zk-compatibility-34.html
需要降低curator的版本到:4.2.0,问题解决
// 为了兼容zookeeper3.4.x,采用低版本的curator
compile("org.apache.curator:curator-x-discovery:4.2.0") {
exclude group: "org.apache.zookeeper", module: "zookeeper"
}
// 引入低版本的zookeeper
compile("org.apache.zookeeper:zookeeper:3.4.14")