开发者学堂课程【精通Spring Cloud Alibaba:LoadBalanced实现的原理】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/634/detail/10077
LoadBalanced 实现的原理
public class RibbonLoadBalancerClient implements LoadBalancerClient中RibbonLoadBalancerClient 相当实现了LoadBalancerClient,RibbonLoadBalancerClient 是子类。
源码:
@override
public ServiceInstance choose(String serviceId){
Server server = getServer( serviceId);
if (server == null) {
return null;
}
return new RibbonServer(serviceId,server, isSecure(server,serviceId),
serverIntrospector( serviceId).getMetadata(server));
}
创建一个服务,调用 getLoadBalancer(serviceId) 方法,再调用 LoadBalancer getLoadBalancer(String serviceId) ,getLoadBalancer(serviceId),访问到接口。
Ribbon 支持的算法有:
AvailabilityFilteringRule
BestAvailableRule
ClientConfigEnabledRoundRobinRule
PredicateBasedRule
RandomRule
RetryRule
RoundRobinRule