Select one from multiple service providers for invocation.
org.apache.dubbo.rpc.cluster.LoadBalance
<dubbo:protocol loadbalance="xxx" />
<!-- Default value settings, when <dubbo:protocol> does not configure loadbalance, this configuration is used -->
<dubbo:provider loadbalance="xxx" />
org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance
org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance
org.apache.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance
org.apache.dubbo.rpc.cluster.loadbalance.ConsistentHashLoadBalance
org.apache.dubbo.rpc.cluster.loadbalance.ShortestResponseLoadBalance
Maven project structure:
src
|-main
|-java
|-com
|-xxx
|-XxxLoadBalance.java (implements LoadBalance interface)
|-resources
|-META-INF
|-dubbo
|-org.apache.dubbo.rpc.cluster.LoadBalance (plain text file, content: xxx=com.xxx.XxxLoadBalance)
XxxLoadBalance.java:
package com.xxx;
import org.apache.dubbo.rpc.cluster.LoadBalance;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.RpcException;
public class XxxLoadBalance implements LoadBalance {
public <T> Invoker<T> select(List<Invoker<T>> invokers, Invocation invocation) throws RpcException {
// ...
}
}
META-INF/dubbo/org.apache.dubbo.rpc.cluster.LoadBalance:
xxx=com.xxx.XxxLoadBalance