You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@curator.apache.org by RATAN KUMAR YADAV <ra...@gmail.com> on 2016/03/02 07:21:09 UTC

how to avoid keep trying to connect with zk with curator

Hi Team,


I am creating zk connection with curator , which keep retry to connect with
zookeeper if it not available and blocking my application .
Is there any way to stop this infinite loop to retry. I am getting below
exception per second and which keep going after calling of client.start().

java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at
sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
    at
org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)

Below code I am using:
final RetryPolicy retryPolicy = new ExponentialBackoffRetry(
BASE_SLEEP_TIME_MS, MAX_RETRIES );
            client = CuratorFrameworkFactory.newClient( CONNECTION_STRING,
retryPolicy );

            client.blockUntilConnected( 5, TimeUnit.SECONDS );
            client.start();


Thanks,
Ratan

Re: how to avoid keep trying to connect with zk with curator

Posted by Cameron McKenzie <mc...@gmail.com>.
hey Ratan,
You don't need to call blockUntilConnected. You can just call start() and
it will handle connection establishment etc. in the background. Obviously,
none of your operations will succeed until you have a connection.
cheers

On Wed, Mar 2, 2016 at 5:21 PM, RATAN KUMAR YADAV <ra...@gmail.com>
wrote:

> Hi Team,
>
>
> I am creating zk connection with curator , which keep retry to connect with
> zookeeper if it not available and blocking my application .
> Is there any way to stop this infinite loop to retry. I am getting below
> exception per second and which keep going after calling of client.start().
>
> java.net.ConnectException: Connection refused
>     at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
>     at
> sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
>     at
>
> org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
>     at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)
>
> Below code I am using:
> final RetryPolicy retryPolicy = new ExponentialBackoffRetry(
> BASE_SLEEP_TIME_MS, MAX_RETRIES );
>             client = CuratorFrameworkFactory.newClient( CONNECTION_STRING,
> retryPolicy );
>
>             client.blockUntilConnected( 5, TimeUnit.SECONDS );
>             client.start();
>
>
> Thanks,
> Ratan
>