Netfilx Ribbon核心接口
实际请求客户端
LoadBalancerClient
RibbonLoadBalancerClient
负载均衡上下文
LoadBalanceContext
RibbonLoadBalanceContext
负载均衡器
lLoadBalancer
BaseLoadBalancer
DynamicServerListLoadBalancer
ZoneAwareLoadBalancer
NoOpLoadBalancer
规则接口
IRule
随机规则 : RandomRule
最可用规则 : BestAvailableRule
轮循规则 : RoundRobinRule
重试实现 : RetryRule
客户端配置: ClientConfigEnabledRoundRobinRule
可过滤性规则 : AvailabilityFilteringRule
RT权重规则:WeightedResponseTimeRule
规避区域规则:ZoneAvoidanceRule
PING策略 查看的机器是活着
IPingStrategy
NoOping
DummyPing
PingConstant
PingUrl
NIWSDiscoveryPing
负载均衡客户端
主要职责
LoadBalancerClient
转化url : 将含应用名称URL转换成具体主机+端口形式
选择服务实例:通过负载均衡算法,指定服务器中的一台实例
请求执行回调:针对选择后服务实例,执行具体的请求回调操作
默认实现
RibbonLoadBalancerClient
自动装配
RibbonAutoConfiguration#loadBalancerClient()
LoadBalancerContext
转化Url : 将含应用名称URL转换成具体主机+端口形式
组件关联:关联RetryHandler,ILoadBalancer等
记录服务统计信息,记录请求相应时间,错误数量等
默认实现:RibbonLoadBalancerContext
自动装配
RibbonAutoConfiguration#loadBalancerContext()
ILoadBalancer
主要职责
增加服务器
获取服务器: 通过关联key获取,获取所有服务列表,获取可用服务列表
服务器状态:标记服务器宕机
默认实现: ZonnAwareLoadBalancer
自动装配:RibbonAutoConfiguration#ribbonLoadBalancer()
IRule
主要职责
选择服务器:根据负载均衡器以及关联key,获取候选服务器
默认实现:ZoneAvoidanceRule
自动装配:RibbonAutoConfiguration#ribbonRule()
IPing
主要职责
活动检测:根据指定服务器,检测其是否活动
默认实现:Dummyping
自动装配:RibbonAutoConfiguration#ribbonPing()
服务器列表
ServerList
主要职责
获取初始化服务器列表
获取更新服务器列表
默认实现:ConfigurationBasedServerList或DiscoveryEnabledNiWSServerList
自动装配:RibbonAutoConfiguration#
Netflix Ribbon 自动装配
RibbonAutoConfiguration
LoadBalancerClient
PropertiesFactory
LoadBalancerAutoConfiguration
@LoadBalanced
RestTemplate
Ribbon客户端配置
RibbonClientConfiguration
LoadBalancerContext
IRule
IPing
ServerList
ILoadBalancer
IClientConfig
Netflix Ribbon配置化组件
PropertiesFactory
ILoadBalancer
iPing
IRule
ServerList
ServerListFilter
调用链路
选择服务器逻辑
LoadBalancerClient(RibbonLoadBalancerClient)->ILoadBalancer(ZonnAwareLoadBalancer)->IRule(ZoneAvoidanceRule)