SolrJ: build a SolrClient(-connection) with HttpClientUtil

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

SolrJ: build a SolrClient(-connection) with HttpClientUtil

Clemens Wyss DEV
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
Reply | Threaded
Open this post in threaded view
|

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

☼ R Nair
Pls use CloudSolrClient.builder(...).withHttpClient(...).
Best, Ravion

On Mon, Aug 13, 2018, 2:40 PM Clemens Wyss DEV <[hidden email]> 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
>
Reply | Threaded
Open this post in threaded view
|

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

☼ R Nair
Or HttpSolrClient.builder as well

On Mon, Aug 13, 2018, 2:50 PM ☼ R Nair <[hidden email]> wrote:

> Pls use CloudSolrClient.builder(...).withHttpClient(...).
> Best, Ravion
>
> On Mon, Aug 13, 2018, 2:40 PM Clemens Wyss DEV <[hidden email]>
> 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
>>
>
Reply | Threaded
Open this post in threaded view
|

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

Shawn Heisey-2
In reply to this post by Clemens Wyss DEV
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