You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Clemens Wyss DEV <cl...@mysign.ch> on 2018/08/13 18:39:49 UTC

SolrJ: build a SolrClient(-connection) with HttpClientUtil

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, ... )

Up till now (Solr 6.6.0) a ll I did was:
solrClient = new HttpSolrClient( coreUrl );
((HttpSolrClient)solrClient).setSoTimeout( forUpdating ? updateSocketTimeout : querySocketTimeout );

Thx
Clemens

Re: SolrJ: build a SolrClient(-connection) with HttpClientUtil

Posted by ☼ R Nair <ra...@gmail.com>.
Or HttpSolrClient.builder as well

On Mon, Aug 13, 2018, 2:50 PM ☼ R Nair <ra...@gmail.com> wrote:

> Pls use CloudSolrClient.builder(...).withHttpClient(...).
> Best, Ravion
>
> On Mon, Aug 13, 2018, 2:40 PM Clemens Wyss DEV <cl...@mysign.ch>
> 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,
>> ... )
>>
>> Up till now (Solr 6.6.0) a ll I did was:
>> solrClient = new HttpSolrClient( coreUrl );
>> ((HttpSolrClient)solrClient).setSoTimeout( forUpdating ?
>> updateSocketTimeout : querySocketTimeout );
>>
>> Thx
>> Clemens
>>
>

Re: SolrJ: build a SolrClient(-connection) with HttpClientUtil

Posted by ☼ R Nair <ra...@gmail.com>.
Pls use CloudSolrClient.builder(...).withHttpClient(...).
Best, Ravion

On Mon, Aug 13, 2018, 2:40 PM Clemens Wyss DEV <cl...@mysign.ch> 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,
> ... )
>
> Up till now (Solr 6.6.0) a ll I did was:
> solrClient = new HttpSolrClient( coreUrl );
> ((HttpSolrClient)solrClient).setSoTimeout( forUpdating ?
> updateSocketTimeout : querySocketTimeout );
>
> Thx
> Clemens
>

Re: SolrJ: build a SolrClient(-connection) with HttpClientUtil

Posted by Shawn Heisey <ap...@elyograg.org>.
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