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. 
 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"); LBHttp2SolrClient.Builder.setAliveCheckInterval(int, TimeUnit), 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 set up 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
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classLBHttp2SolrClient.Builder- 
Nested classes/interfaces inherited from class org.apache.solr.client.solrj.impl.LBSolrClientLBSolrClient.Endpoint, LBSolrClient.Req, LBSolrClient.Rsp, LBSolrClient.ServerIterator, LBSolrClient.ServerWrapper
 
- 
 - 
Field Summary- 
Fields inherited from class org.apache.solr.client.solrj.impl.LBSolrClientaliveCheckIntervalMillis, parser, requestWriter, RETRY_CODES, UPDATE_LIVE_SERVER_MESSAGE, zombieServers
 - 
Fields inherited from class org.apache.solr.client.solrj.SolrClientdefaultCollection
 
- 
 - 
Constructor SummaryConstructors Constructor Description LBHttp2SolrClient(Http2SolrClient solrClient, String... baseSolrUrls)Deprecated.UseLBHttp2SolrClient.Builderinstead
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddQueryParams(String queryOnlyParam)Deprecated.you should instead set this on the passed in Http2SolrClient used by the Builder.CancellableasyncReq(LBSolrClient.Req req, AsyncListener<LBSolrClient.Rsp> asyncListener)Deprecated.UserequestAsync(Req).protected SolrClientgetClient(String baseUrl)Deprecated.UsegetClient(Endpoint)instead.protected SolrClientgetClient(LBSolrClient.Endpoint endpoint)ResponseParsergetParser()RequestWritergetRequestWriter()Set<String>getUrlParamNames()CompletableFuture<LBSolrClient.Rsp>requestAsync(LBSolrClient.Req req)Execute an asynchronous request against one or more hosts for a given collection.voidsetParser(ResponseParser parser)Deprecated.Pass in a configuredHttp2SolrClientinsteadvoidsetQueryParams(Set<String> queryParams)Deprecated.You should instead set this on the passed in Http2SolrClient used by the Builder.voidsetRequestWriter(RequestWriter writer)Deprecated.Pass in a configuredHttp2SolrClientinstead- 
Methods inherited from class org.apache.solr.client.solrj.impl.LBSolrClientaddSolrServer, addSolrServer, close, createServerWrapper, doRequest, doRequest, makeServerAZombie, makeServerAZombie, makeServerAZombie, normalize, pickServer, removeSolrEndpoint, removeSolrServer, request, request, request, reviveZombieServer, reviveZombieServer, setAliveCheckInterval, updateAliveList
 - 
Methods inherited from class org.apache.solr.client.solrj.SolrClientadd, 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, getDefaultCollection, optimize, optimize, optimize, optimize, optimize, optimize, ping, ping, query, query, query, query, queryAndStreamResponse, queryAndStreamResponse, queryAndStreamResponse, request, rollback, rollback
 
- 
 
- 
- 
- 
Constructor Detail- 
LBHttp2SolrClient@Deprecated public LBHttp2SolrClient(Http2SolrClient solrClient, String... baseSolrUrls) Deprecated.UseLBHttp2SolrClient.Builderinstead
 
- 
 - 
Method Detail- 
getClient@Deprecated protected SolrClient getClient(String baseUrl) Deprecated.UsegetClient(Endpoint)instead.- Specified by:
- getClientin class- LBSolrClient
 
 - 
getClientprotected SolrClient getClient(LBSolrClient.Endpoint endpoint) - Specified by:
- getClientin class- LBSolrClient
 
 - 
setParser@Deprecated public void setParser(ResponseParser parser) Deprecated.Pass in a configuredHttp2SolrClientinsteadNote: This setter method is not thread-safe.- Overrides:
- setParserin class- LBSolrClient
- 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()
 
 - 
getParserpublic ResponseParser getParser() - Overrides:
- getParserin class- LBSolrClient
 
 - 
setRequestWriter@Deprecated public void setRequestWriter(RequestWriter writer) Deprecated.Pass in a configuredHttp2SolrClientinsteadChoose theRequestWriterto use.By default, BinaryRequestWriteris used.Note: This setter method is not thread-safe. - Overrides:
- setRequestWriterin class- LBSolrClient
- Parameters:
- writer- Default RequestWriter, used to encode requests sent to the server.
 
 - 
getRequestWriterpublic RequestWriter getRequestWriter() - Overrides:
- getRequestWriterin class- LBSolrClient
 
 - 
setQueryParams@Deprecated public void setQueryParams(Set<String> queryParams) Deprecated.You should instead set this on the passed in Http2SolrClient used by the Builder.
 - 
addQueryParams@Deprecated public void addQueryParams(String queryOnlyParam) Deprecated.you should instead set this on the passed in Http2SolrClient used by the Builder.This method should be removed as being able to add a query parameter isn't compatible with the idea that query params are an immutable property of a solr client.
 - 
asyncReq@Deprecated public Cancellable asyncReq(LBSolrClient.Req req, AsyncListener<LBSolrClient.Rsp> asyncListener) Deprecated.UserequestAsync(Req).Execute an asynchronous request against a one or more hosts for a given collection.- Parameters:
- req- the wrapped request to perform
- asyncListener- callers should provide an implementation to handle events: start, success, exception
- Returns:
- Cancellable allowing the caller to attempt cancellation
 
 - 
requestAsyncpublic CompletableFuture<LBSolrClient.Rsp> requestAsync(LBSolrClient.Req req) Execute an asynchronous request against one or more hosts for a given collection. The passed-in Req object includes a List of Endpoints. This method always begins with the first Endpoint in the list and if unsuccessful tries each in turn until the request is successful. Consequently, this method does not actually Load Balance. It is up to the caller to shuffle the List of Endpoints if Load Balancing is desired.- Parameters:
- req- the wrapped request to perform
- Returns:
- a CompletableFuturethat tracks the progress of the async request.
 
 
- 
 
-