public class LBHttpSolrClient extends LBSolrClient
HttpSolrClient. This is useful when you
have multiple Solr servers and the requests need to be Load Balanced among them.
Do NOT use this class for indexing in leader/follower scenarios since documents must be sent to the
correct leader; no inter-node routing is done.
In SolrCloud (leader/replica) scenarios, it is usually better to use
CloudSolrClient, but this class may be used
for updates because the server will forward them to the appropriate leader.
It offers automatic failover when a server goes down and it detects when the server comes back up.
Load balancing is done using a simple round-robin on the list of servers.
If a request to a server fails by an IOException due to a connection timeout or read timeout then the host is taken off the list of live servers and moved to a 'dead server list' and the request is resent to the next live server. This process is continued till it tries all the live servers. If at least one server is alive, the request succeeds, and if not it fails.
SolrClient lbHttpSolrClient = new LBHttpSolrClient("http://host1:8080/solr/", "http://host2:8080/solr", "http://host2:8080/solr");
//or if you wish to pass the HttpClient do as follows
httpClient httpClient = new HttpClient();
SolrClient lbHttpSolrClient = new LBHttpSolrClient(httpClient, "http://host1:8080/solr/", "http://host2:8080/solr", "http://host2:8080/solr");
This detects if a dead server comes alive automatically. The check is done in fixed intervals in a dedicated thread.
This interval can be set using LBSolrClient.setAliveCheckInterval(int) , the default is set to one minute.
When to use this?
This can be used as a software load balancer when you do not wish to setup an external
load balancer. Alternatives to this code are to use
a dedicated hardware load balancer or using Apache httpd with mod_proxy_balancer as a load balancer. See Load balancing on Wikipedia
| 限定符和类型 | 类和说明 |
|---|---|
static class |
LBHttpSolrClient.Builder
Constructs
LBHttpSolrClient instances from provided configuration. |
static class |
LBHttpSolrClient.Req
已过时。
use
LBSolrClient.Req instead |
static class |
LBHttpSolrClient.Rsp
已过时。
use
LBSolrClient.Rsp instead |
LBSolrClient.ServerWrapperparser, queryParams, requestWriter| 限定符 | 构造器和说明 |
|---|---|
protected |
LBHttpSolrClient(org.apache.http.client.HttpClient httpClient,
ResponseParser parser,
String... solrServerUrl)
已过时。
use
LBHttpSolrClient(Builder) instead, as it is a more extension/subclassing-friendly alternative |
protected |
LBHttpSolrClient(HttpSolrClient.Builder httpSolrClientBuilder,
org.apache.http.client.HttpClient httpClient,
String... solrServerUrl)
已过时。
use
LBHttpSolrClient(Builder) instead, as it is a more extension/subclassing-friendly alternative |
protected |
LBHttpSolrClient(LBHttpSolrClient.Builder builder) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close() |
protected SolrClient |
getClient(String baseUrl) |
org.apache.http.client.HttpClient |
getHttpClient()
Return the HttpClient this instance uses.
|
protected HttpSolrClient |
makeSolrClient(String server) |
String |
removeSolrServer(String server) |
LBHttpSolrClient.Rsp |
request(LBHttpSolrClient.Req req)
已过时。
use
LBSolrClient.request(LBSolrClient.Req) instead |
void |
setConnectionTimeout(int timeout)
已过时。
since 7.0 Use
LBHttpSolrClient.Builder methods instead. |
void |
setSoTimeout(int timeout)
已过时。
since 7.0 Use
LBHttpSolrClient.Builder methods instead. |
addQueryParams, addSolrServer, createServerWrapper, doRequest, getParser, getQueryParams, getRequestWriter, normalize, pickServer, request, request, request, setAliveCheckInterval, setParser, setQueryParams, setRequestWriter, updateAliveListadd, add, add, add, add, add, add, add, add, add, addBean, addBean, addBean, addBean, addBeans, addBeans, addBeans, addBeans, addBeans, addBeans, commit, commit, commit, commit, commit, commit, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteByQuery, deleteByQuery, deleteByQuery, deleteByQuery, getBinder, getById, getById, getById, getById, getById, getById, getById, getById, optimize, optimize, optimize, optimize, optimize, optimize, ping, ping, query, query, query, query, queryAndStreamResponse, queryAndStreamResponse, queryAndStreamResponse, request, rollback, rollback@Deprecated protected LBHttpSolrClient(HttpSolrClient.Builder httpSolrClientBuilder, org.apache.http.client.HttpClient httpClient, String... solrServerUrl)
LBHttpSolrClient(Builder) instead, as it is a more extension/subclassing-friendly alternative@Deprecated protected LBHttpSolrClient(org.apache.http.client.HttpClient httpClient, ResponseParser parser, String... solrServerUrl)
LBHttpSolrClient(Builder) instead, as it is a more extension/subclassing-friendly alternativeprotected LBHttpSolrClient(LBHttpSolrClient.Builder builder)
protected HttpSolrClient makeSolrClient(String server)
@Deprecated public void setConnectionTimeout(int timeout)
LBHttpSolrClient.Builder methods instead.@Deprecated public void setSoTimeout(int timeout)
LBHttpSolrClient.Builder methods instead.@Deprecated public LBHttpSolrClient.Rsp request(LBHttpSolrClient.Req req) throws SolrServerException, IOException
LBSolrClient.request(LBSolrClient.Req) insteadprotected SolrClient getClient(String baseUrl)
getClient 在类中 LBSolrClientpublic String removeSolrServer(String server)
removeSolrServer 在类中 LBSolrClientpublic void close()
close 在接口中 Closeableclose 在接口中 AutoCloseableclose 在类中 LBSolrClientpublic org.apache.http.client.HttpClient getHttpClient()
Copyright © 2006–2022 The Apache Software Foundation. All rights reserved.