Fjordo
Fjordo

Reputation: 872

How to check Solr Status with SolrPing

I need to check if Solr machine and Solr service are up and running; I have a java server who need to know that. I use SolrJ library to communicate with Solr and query it. I use Solr 7.3.0 I think I can test Solr status with SolrPing class, but I always get this exception.

Server refused connection at: http://localhost:8983/solr

this is my solr ping call

SolrClient solrClient = new HttpSolrClient(solrBaseUrl);
SolrPing solrPing = new SolrPing();
SolrPingResponse pingResponse = solrPing.process(solrClient);
int status = pingResponse.getStatus();
System.out.println(status);

What do I miss ? It fails on .process call. solrBaseUrl is correct, and my solr istance is shutted down (so I should expect something like status -1)

Thanks to you all

Upvotes: 0

Views: 1698

Answers (1)

MatsLindh
MatsLindh

Reputation: 52802

Since you're getting the exception, catch the exception and return -1 (or do whatever means "this service is down" in your application).

If you've decided that this means -1, that's up to you.

The process method is a general method in SolrJ that sends a command/request to the server, and a connection error exception is a general response exception thrown by the method when it can't connect to the server (and thus, most commands will have an undefined state - the ping command might possibly be the only exception to this).

Upvotes: 2

Related Questions