Class LBHttp2SolrClient
- java.lang.Object
-
- org.apache.solr.client.solrj.SolrClient
-
- org.apache.solr.client.solrj.impl.LBSolrClient
-
- org.apache.solr.client.solrj.impl.LBHttp2SolrClient
-
- All Implemented Interfaces:
Closeable
,Serializable
,AutoCloseable
public class LBHttp2SolrClient extends LBSolrClient
LBHttp2SolrClient or "LoadBalanced LBHttp2SolrClient" is a load balancing wrapper aroundHttp2SolrClient
. 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 lbHttp2SolrClient = new LBHttp2SolrClient(http2SolrClient, "http://host1:8080/solr/", "http://host2:8080/solr", "http://host2:8080/solr");
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- Since:
- solr 8.0
- See Also:
- Serialized Form
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.solr.client.solrj.impl.LBSolrClient
LBSolrClient.Req, LBSolrClient.Rsp, LBSolrClient.ServerIterator, LBSolrClient.ServerWrapper
-
-
Field Summary
-
Fields inherited from class org.apache.solr.client.solrj.impl.LBSolrClient
parser, queryParams, requestWriter, RETRY_CODES, zombieServers
-
-
Constructor Summary
Constructors Constructor Description LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addQueryParams(String queryOnlyParam)
Cancellable
asyncReq(LBSolrClient.Req req, AsyncListener<LBSolrClient.Rsp> asyncListener)
protected SolrClient
getClient(String baseUrl)
void
setParser(ResponseParser parser)
Changes theResponseParser
that will be used for the internal SolrServer objects.void
setQueryParams(Set<String> queryParams)
Expert Method.void
setRequestWriter(RequestWriter writer)
Changes theRequestWriter
that will be used for the internal SolrServer objects.-
Methods inherited from class org.apache.solr.client.solrj.impl.LBSolrClient
addSolrServer, addZombie, close, createServerWrapper, doRequest, getParser, getQueryParams, getRequestWriter, normalize, pickServer, removeSolrServer, request, request, request, setAliveCheckInterval, updateAliveList
-
Methods inherited from class org.apache.solr.client.solrj.SolrClient
add, 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, getContext, optimize, optimize, optimize, optimize, optimize, optimize, ping, ping, query, query, query, query, queryAndStreamResponse, queryAndStreamResponse, queryAndStreamResponse, request, rollback, rollback
-
-
-
-
Constructor Detail
-
LBHttp2SolrClient
public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls)
-
-
Method Detail
-
getClient
protected SolrClient getClient(String baseUrl)
- Specified by:
getClient
in classLBSolrClient
-
setParser
public void setParser(ResponseParser parser)
Description copied from class:LBSolrClient
Changes theResponseParser
that will be used for the internal SolrServer objects.- Overrides:
setParser
in classLBSolrClient
- Parameters:
parser
- Default Response Parser chosen to parse the response if the parser were not specified as part of the request.- See Also:
SolrRequest.getResponseParser()
-
setRequestWriter
public void setRequestWriter(RequestWriter writer)
Description copied from class:LBSolrClient
Changes theRequestWriter
that will be used for the internal SolrServer objects.- Overrides:
setRequestWriter
in classLBSolrClient
- Parameters:
writer
- Default RequestWriter, used to encode requests sent to the server.
-
setQueryParams
public void setQueryParams(Set<String> queryParams)
Description copied from class:LBSolrClient
Expert Method.- Overrides:
setQueryParams
in classLBSolrClient
- Parameters:
queryParams
- set of param keys to only send via the query string
-
addQueryParams
public void addQueryParams(String queryOnlyParam)
- Overrides:
addQueryParams
in classLBSolrClient
-
asyncReq
public Cancellable asyncReq(LBSolrClient.Req req, AsyncListener<LBSolrClient.Rsp> asyncListener)
-
-