public class LBHttp2SolrClient extends LBSolrClient
Http2SolrClient
. 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 master/slave scenarios since documents must be sent to the
correct master; 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.
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 usingSolrClient 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
LBSolrClient.Req, LBSolrClient.Rsp, LBSolrClient.ServerWrapper
parser, queryParams, requestWriter
Constructor and Description |
---|
LBHttp2SolrClient(Http2SolrClient httpClient,
String... baseSolrUrls) |
Modifier and Type | Method and Description |
---|---|
protected SolrClient |
getClient(String baseUrl) |
addQueryParams, addSolrServer, close, createServerWrapper, doRequest, getParser, getQueryParams, getRequestWriter, normalize, pickServer, removeSolrServer, request, request, request, setAliveCheckInterval, setParser, setQueryParams, setRequestWriter, updateAliveList
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, optimize, optimize, optimize, optimize, optimize, optimize, ping, query, query, query, query, queryAndStreamResponse, queryAndStreamResponse, queryAndStreamResponse, request, rollback, rollback
public LBHttp2SolrClient(Http2SolrClient httpClient, String... baseSolrUrls)
protected SolrClient getClient(String baseUrl)
getClient
in class LBSolrClient
Copyright © 2000-2019 Apache Software Foundation. All Rights Reserved.