Load Balance Extension
Load Balance Extension
Extension Description
Select one from multiple service providers for invocation.
Extension Interface
org.apache.dubbo.rpc.cluster.LoadBalance
Extension Configuration
<dubbo:protocol loadbalance="xxx" />
<!-- Default value settings, when <dubbo:protocol> does not configure loadbalance, this configuration is used -->
<dubbo:provider loadbalance="xxx" />
Known Extensions
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
Extension Example
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
Feedback
Was this page helpful?
Yes No
Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)