# How best to verify a client connection?

**URL:** <https://discuss.elastic.co/t/how-best-to-verify-a-client-connection/5869>\
**Category:** Elasticsearch\
**Created:** [November 14, 2011, 6:49pm UTC](https://discuss.elastic.co/t/how-best-to-verify-a-client-connection/5869 "2011-11-14T18:49:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [November 14, 2011, 6:49pm UTC](https://discuss.elastic.co/t/how-best-to-verify-a-client-connection/5869/1 "2011-11-14T18:49:42Z")

</div>

I'd like a simple way of verifying that ES is available to a Java  
client. I have a factory that looks something like this to get a  
client instance:

> <https://gist.github.com/digitalsanctum/1364734>

What's the best way to gracefully handle the scenario of ES not being  
available or is what I have sufficient?

---

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [November 14, 2011, 6:54pm UTC](https://discuss.elastic.co/t/how-best-to-verify-a-client-connection/5869/2 "2011-11-14T18:54:38Z")

</div>

I forgot to mention that I get the following debug messages every 5  
seconds. Is there a way to avoid these messages while verifying the  
connection?

13:52:47,365 INFO [STDOUT] elasticsearch[cached]-pool-14-thread-1  
[2011-11-14 13:52:47,365][client.transport]DEBUG: [Orbit] Failed to  
connect to node [#transport#-1][inet[localhost/127.0.0.1:9300]],  
removed from nodes list  
org.elasticsearch.transport.ConnectTransportException:   
[inet[localhost/127.0.0.1:9300]] connect\_timeout[30s]  
at  
org.elasticsearch.transport.netty.NettyTransport.connectToChannels(NettyTransport.java:  
563)  
at  
org.elasticsearch.transport.netty.NettyTransport.connectToNode(NettyTransport.java:  
506)  
at  
org.elasticsearch.transport.netty.NettyTransport.connectToNode(NettyTransport.java:  
485)  
at  
org.elasticsearch.transport.TransportService.connectToNode(TransportService.java:  
121)  
at org.elasticsearch.client.transport.TransportClientNodesService  
$SimpleNodeSampler.sample(TransportClientNodesService.java:260)  
at org.elasticsearch.client.transport.TransportClientNodesService  
$ScheduledNodeSampler.run(TransportClientNodesService.java:243)  
at java.util.concurrent.ThreadPoolExecutor  
$Worker.runTask(ThreadPoolExecutor.java:886)  
at java.util.concurrent.ThreadPoolExecutor  
$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:680)  
Caused by: java.net.ConnectException: Connection refused  
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)  
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:  
567)  
at  
org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink  
$Boss.connect(NioClientSocketPipelineSink.java:384)  
at  
org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink  
$Boss.processSelectedKeys(NioClientSocketPipelineSink.java:354)  
at  
org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink  
$Boss.run(NioClientSocketPipelineSink.java:276)  
at  
org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:  
108)  
at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker  
$1.run(DeadLockProofWorker.java:44)  
... 3 more

On Nov 14, 1:49 pm, Shane Witbeck [sh...@digitalsanctum.com](mailto:sh...@digitalsanctum.com) wrote:

> I'd like a simple way of verifying that ES is available to a Java  
> client. I have a factory that looks something like this to get a  
> client instance:
> 
> [factory for getting ES client · GitHub](https://gist.github.com/1364734)
> 
> What's the best way to gracefully handle the scenario of ES not being  
> available or is what I have sufficient?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 15, 2011, 1:51pm UTC](https://discuss.elastic.co/t/how-best-to-verify-a-client-connection/5869/3 "2011-11-15T13:51:41Z")

</div>

Yes, what you did looks good. It will continue to try and reconnect in the  
background though, so if you throw an exception if it has not connected,  
you might want to close the client as well.

On Mon, Nov 14, 2011 at 8:49 PM, Shane Witbeck [shane@digitalsanctum.com](mailto:shane@digitalsanctum.com)wrote:

> I'd like a simple way of verifying that ES is available to a Java  
> client. I have a factory that looks something like this to get a  
> client instance:
> 
> [factory for getting ES client · GitHub](https://gist.github.com/1364734)
> 
> What's the best way to gracefully handle the scenario of ES not being  
> available or is what I have sufficient?

---

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [November 15, 2011, 3:04pm UTC](https://discuss.elastic.co/t/how-best-to-verify-a-client-connection/5869/4 "2011-11-15T15:04:24Z")

</div>

Thanks! The addition of closing the client prevents the retries and  
debug messages.

On Nov 15, 8:51 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Yes, what you did looks good. It will continue to try and reconnect in the  
> background though, so if you throw an exception if it has not connected,  
> you might want to close the client as well.
> 
> On Mon, Nov 14, 2011 at 8:49 PM, Shane Witbeck [sh...@digitalsanctum.com](mailto:sh...@digitalsanctum.com)wrote:
> 
> > I'd like a simple way of verifying that ES is available to a Java  
> > client. I have a factory that looks something like this to get a  
> > client instance:
> 
> > [https://gist.github.com/1364734](https://gist.github.com/1364734)
> 
> > What's the best way to gracefully handle the scenario of ES not being  
> > available or is what I have sufficient?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:48am UTC](https://discuss.elastic.co/t/how-best-to-verify-a-client-connection/5869/5 "2017-07-06T03:48:34Z")

</div>


