我试图将Apache Curator与dockerized zookeeper实例一起使用,无论我如何尝试连接,我总是最终得到一个
org.apache.zookeeper.KeeperException $ UnimplementedException: KeeperErrorCode =未实现...
错误。我已经尝试了解文档,但我没有到达任何地方。我已登录到zookeeper CLI并确保端口号正确无误:
snerd@powerglove:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 31f1093495ba compose_zookeeper "/opt/zookeeper/bin/ 3 weeks ago Up About a minute 0.0.0.0:32770->2181/tcp,
0.0.0.0:32769->2888/tcp, 0.0.0.0:32768->3888/tcp zookeeper
这是我尝试使用的代码:
public class App {
public static void main( String[] args ) {
CuratorFramework client = CuratorFrameworkFactory.newClient("0.0.0.0:32770", new RetryUntilElapsed(3000, 1000));
client.start();
try {
client.create().forPath("/larry-smells/foop", "tuna?".getBytes());
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
据我所知Curator getting started page,这应该有效。我错过了什么?
EDIT1 我发现我能够从动物园管理员合奏中抽出数据:
System.out.println(new String(curatorFramework.getData().forPath("/larry-smells")));
但是创建命令仍然在爆炸。
edit2
错误的堆栈跟踪:
org.apache.zookeeper.KeeperException $ UnimplementedException: KeeperErrorCode =未实现/ larry-smells / foop at org.apache.zookeeper.KeeperException.create(KeeperException.java:103) 在 org.apache.zookeeper.KeeperException.create(KeeperException.java:51) 在org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:1297)at org.apache.curator.framework.imps.CreateBuilderImpl $ 17.call(CreateBuilderImpl.java:1040) 在 org.apache.curator.framework.imps.CreateBuilderImpl $ 17.call(CreateBuilderImpl.java:1023) 在 org.apache.curator.connection.StandardConnectionHandlingPolicy.callWithRetry(StandardConnectionHandlingPolicy.java:67) 在org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:99)at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1020) 在 org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:501) 在 org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:491) 在 org.apache.curator.framework.imps.CreateBuilderImpl $ 4.forPath(CreateBuilderImpl.java:367) 在 org.apache.curator.framework.imps.CreateBuilderImpl $ 4.forPath(CreateBuilderImpl.java:309) 在com.mycompany.app.App.main(App.java:35)
答案 0 :(得分:38)
编辑:如果您使用Curator与Zookeeper的错误组合,显然会出现此错误。来自curator.apache.org:
Curator 2.x.x - 兼容ZooKeeper 3.4.x和ZooKeeper 3.5.x
Curator 3.x.x - 仅与ZooKeeper 3.5.x兼容,并支持动态重新配置等新功能。
仅使用错误代码而非堆栈跟踪很难确定您的问题,但我建议您使应用程序更稳定的一些改进是:
public class App {
public static void main( String[] args ) {
CuratorFramework client = CuratorFrameworkFactory.newClient("0.0.0.0:32770", new RetryUntilElapsed(3000, 1000));
client.start();
try {
//make sure you're connected to zookeeper.
client.blockUntilConnected();
//Make sure the parents are created.
client.create().creatingParentsIfNeeded().forPath("/larry-smells/foop", "tuna?".getBytes());
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
答案 1 :(得分:2)
我遇到了同样的问题。
我尝试使用inTransaction(),如下所述:http://www.programcreek.com/java-api-examples/index.php?api=org.apache.curator.framework.CuratorFramework练习6 似乎工作。
client.inTransaction ().create().forPath("/larry-smells/foop", "tuna?".getBytes()).and ().commit ();
答案 2 :(得分:2)
我也遇到了类似的异常,我使用了以下兼容的依赖项,可以帮助我解决该异常。
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
<version>4.0.1</version>
</dependency>
答案 3 :(得分:0)
该问题是由于不兼容而引起的。
要解决此问题,您需要更改版本,如下所述:
https://curator.apache.org/zk-compatibility.html
如果这不起作用,只需查找最新的策展人版本,该版本取决于3.4.x zookeeper版本(目前为'2.12.0'
)。
答案 4 :(得分:0)
@Massimo Da Ros解决方案有效,但在新版本中,Curator 4.0.0 inTransaction已弃用,它的推荐使用transaction
方法如下所示:
CuratorOp op = client.transactionOp().create()
.withMode(CreateMode.PERSISTENT)
.withACL(Ids.OPEN_ACL_UNSAFE)
.forPath("/test", "Data".getBytes());
result = client.transaction().forOperations(op).get(0).toString();