I tested to catch and ignore the exception from registerService() and then after ZK becomes available it seems that my application has not been registered in Service Discovery. I will dig into this a bit more and open an issue. Thanks!
On 14 May 2014 15:42, Jordan Zimmerman <[email protected]> wrote: > You can safely ignore the exception as Curator will re-register the > service when the connection heals. That said, it seems to me > that registerService() should do its work in the background. Please open an > issue for this. > > -JZ > > > From: Olli Miettinen [email protected] > Reply: [email protected] [email protected] > Date: May 14, 2014 at 3:11:22 AM > To: [email protected] [email protected] > Subject: How to recover if ZK is unavailable at Curator start up? > > Hello, > > I'm using Curator Discovery Service to register my application's host IP > address to Zookeeper. > (Curator 2.4.2 and Zookeeper 3.4.5) > > If Zookeeper cluster is unavailable to my application at start-up, an > exception is thrown from ServiceDiscovery.registerService() after retries > are finished. > > I need my app to retry until it successfully registers to Discovery > Service so can't use the RetryPolicy as it seems to have a limited max > number of retries. > > Should I maybe observe the ZK connection state and register to Discover > Service only after successfully connected? > Or catch the exception and implement my own retry of registering when > RetryPolicy runs out of retries? > Other suggestions? > > This is my code: > > CuratorFramework client = ... > ServiceDiscovery<InstanceDetails> serviceDiscovery = ... > ServiceInstance<InstanceDetails> serviceInstance = ... > > public void start() throws Exception { > client.start(); > serviceDiscovery.start(); > serviceDiscovery.registerService(serviceInstance); > // ... > } > > Here's the exception I get at serviceDiscovery.registerService() > > 2014-05-13 16:04:25,315 [main] DEBUG org.apache.curator.RetryLoop : Retry > policy not allowing retry > Exception in thread "main" > org.apache.zookeeper.KeeperException$ConnectionLossException: > KeeperErrorCode = ConnectionLoss for /discovery/myapp/10.36.101.36 > at org.apache.zookeeper.KeeperException.create(KeeperException.java:99) > at org.apache.zookeeper.KeeperException.create(KeeperException.java:51) > at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:783) > at > org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:676) > at > org.apache.curator.framework.imps.CreateBuilderImpl$11.call(CreateBuilderImpl.java:660) > at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:107) > at > org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:657) > at > org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:441) > at > org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:431) > at > org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:44) > at > org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.internalRegisterService(ServiceDiscoveryImpl.java:176) > at > org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.registerService(ServiceDiscoveryImpl.java:150) > at > com.mycompany.zookeeper.discovery.MyDiscoveryClient.start(MyDiscoveryClient.java:51) > > Thanks for any advice, > Olli > >
