On 8/13/2018 12:39 PM, Clemens Wyss DEV wrote:
What is the proposed way to get/build a SolrClient(-connection) via
HttpClientUtil
- respecting a given connection and response (socket) timeout (ROP_SO_TIMEOUT,
PROP_CONNECTION_TIMEOUT)
- making reuse of underlying http client (pooling?)
- what else makes sense (such as PROP_ALLOW_COMPRESSION, PROP_USE_RETRY, ... )
Here's a basic way to create HttpSolrClient, using 7.4 API:
String baseUrl = "http://solr.example.com:8983/solr";
SolrClient sc = null;
Builder sb = new HttpSolrClient.Builder(baseUrl);
sb.withSocketTimeout(60000);
sb.withConnectionTimeout(5000);
sb.allowCompression(true);
sc = sb.build();
Note that the builder methods are fluent. Which means the last six
lines of what I wrote above can be replaced with one statement:
SolrClient sc = new HttpSolrClient.Builder(baseUrl)
.withSocketTimeout(60000).withConnectionTimeout(5000)
.allowCompression(true).build();
The more verbose code style is easier to debug, but won't make any
actual difference in program operation.
If you want to, you can also create a CloseableHttpClient object using
whatever methods you prefer and assign that to the Builder using
sb.withHttpClient(client) instead of all the other methods I used.
If you're trying to create a CloudSolrClient object rather than
HttpSolrClient, there is a similar Builder available for that.
Thanks,
Shawn