Lazy Java Client

Hi all ESers,

I'd like to connect to my cluster from Java lazily, i.e. if the connection is not available, don't fail and keep trying (i.e. when new requests are made). Is such a option available from the library already?

Thanks, Dan.

If I understand correctly, you would like to send requests through e.g. the transport client and have it keep on trying although no nodes are available. That is not supported I'm afraid.

May I ask you to elaborate on the reason behind this requirement?

Hi Luca,

Not quite. I’d like the client to perform the initial connection lazily only, not actual requests.

i.e. component construction sets up a connection configuration, and connects if available, but doesn’t throw an exception if it cannot connect at this time. When the component’s methods are called, it tries to connect again and throws an error if it can’t.

I can write this logic easily enough, but as I know that the client has in-built reconnection logic anyway, I wondered if there is a setting to get it to apply also to the initial connection.

Cheers, Dan.

Thanks for clarifying Daniel.

What client are you using at the moment? If you use the transport client that's part of our java api, it does try to connect to each node when you call TransportClient#addTransportAddress, but it won't throw exception if none of them are available, as long as you don't try to send requests through the execute method. If you do, then you do get back a NoNodeAvailableException if none of the nodes are available.

The transport client does also some node sampling in the background to verify that the nodes are available etc. You can configure the sampling interval through the client.transport.nodes_sampler_interval setting, default is 5 seconds.

Hope this helps

Aha, my mistaken then. I check the existence of an index immediately after and it’s probably that throwing the exception.
Thanks for your help!