How to create a ttl node using apache curator? I have tried the following
ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3);
String connectionString = "127.0.0.1:2181";
CuratorFramework client = CuratorFrameworkFactory.newClient(connectionString, retryPolicy);
client.getUnhandledErrorListenable().addListener((message, e) -> {
System.err.println("error=" + message);
e.printStackTrace();
});
client.getConnectionStateListenable().addListener((c, newState) -> {
System.out.println("state=" + newState);
});
client.start();
Code 1:
PersistentTtlNode persistentTtlNode = new PersistentTtlNode(client, "/stores/abc.com", 10000, "".getBytes());
persistentTtlNode.start();
boolean flag = persistentTtlNode.waitForInitialCreate(1000, TimeUnit.MICROSECONDS);
System.out.println(flag);
persistentTtlNode.close();
Result:
Node is not getting created and the flag is false
Code 2:
client.create().withTtl(1000).creatingParentContainersIfNeeded().withMode(CreateMode.PERSISTENT_WITH_TTL).forPath("/stores/india.com");
Result: Getting the following exception:
Exception in thread "main" org.apache.zookeeper.KeeperException$UnimplementedException: KeeperErrorCode = Unimplemented for /stores/india.com
at org.apache.zookeeper.KeeperException.create(KeeperException.java:106)
at org.apache.zookeeper.KeeperException.create(KeeperException.java:54)
at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:1837)
at org.apache.curator.framework.imps.CreateBuilderImpl$16.call(CreateBuilderImpl.java:1131)
at org.apache.curator.framework.imps.CreateBuilderImpl$16.call(CreateBuilderImpl.java:1113)
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:93)
at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1110)
at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:593)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:583)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:561)
at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:48)
at Main.main(Main.java:67)
What's the correct way to create a node with ttl in apache curator?