【发布时间】:2017-05-24 20:48:06
【问题描述】:
我想知道 Apache Curator 中的 create() 方法是否使用重试逻辑包装了原始 Zookeeper 创建方法?
我编写了一些创建 ZNode 的代码,我希望它默认重试。如果不是,那么编写具有重试功能的 create 函数的最佳方法是什么?
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 parants are created.
client.create().creatingParentsIfNeeded().forPath("/larry-smells/foop", "tuna?".getBytes());
} catch (Exception e) {
System.out.println(e.toString());
}
【问题讨论】:
-
不需要调用client.blockUntilConnected()。仅供参考
标签: apache-zookeeper apache-curator