Ribbon总结
2021-07-02 11:26:38 0 举报
ribbon核心源码的解析,欢迎指正
作者其他创作
大纲/内容
获取服务器列表这里是跟eureka client交互的核心
BaseLoadBalancer.PingTask
请求执行request.execute()
这里server在哪里解析出来了?
启动
serverListUpdater.start(updateAction)
服务器更新serverListUpdater
ServiceA
pingIntervalTime = 30maxTotalPingTime = 2
.DynamicServerListLoadBalancer#restOfInit
LoadBalancerInterceptor
serverListImpl.getUpdatedListOfServers()
ZonePreferenceServerListFilter
InterceptingRequestExecution#execute
SpringClientFactory#getInstance
2
将http://ServiceA/user/sayHello/1转换为http://localhost:8010/user/sayHello/1
getContext(name)上下文
messageConverter.read()
ServerListUpdater
request.apply(serviceInstance)(LoadBalancerRequest)
LoadBalancerAutoConfiguration
心跳
RibbonClientConfiguration#ribbonServerListFilter
触发 scheduleWithFixedDelay每30s拉一次
PollingServerListUpdater
RibbonClientConfiguration#ribbonRule
从context上下文获取this.clientFactory .getLoadBalancerContext(serviceId)
2 组装成http请求数据
ILoadBalancer
组装request
updateAction
1
任务触发
选择servergetServer(loadBalancer)
requestFactory.createRequest()
RibbonClientConfiguration#ribbonClientConfig
server
请求触发restTemplate.getForObject
CompositePredicate#getEligibleServers
BaseLoadBalancer#setPingInterval
loadBalancer.execute()
DynamicServerListLoadBalancer#updateListOfServers
返回响应
LoadBalancerInterceptor#intercept
serviceName(ServiceA)
localRegionApps.get()
serviceRequest
LoadBalancerClient(RibbonLoadBalancerClient)
context.getBean(type);
跳转
HttpMessageConverterExtractor#extractData
创建
RibbonLoadBalancerClient#execute()
ZoneAvoidanceRule
创建一个requestInterceptingClientHttpRequest(LoadBalancerInterceptor、GET)
restTemplate.setInterceptors(list);
EurekaRibbonClientConfiguration#ribbonServerList
request.getURI()
RibbonAutoConfiguration
delegate.execute()
轮询取模AbstractServerPredicate#incrementAndGetModulo
解析host
这里的ILoadBalancer跟ServiceA绑定?
RibbonServer
过滤
enableAndInitLearnNewServersFeature()
NamedContextFactory#getContext
BaseLoadBalancer#initWithConfig
每30s
在这里就单纯的使用eureka client下拉取的节点了
updateAction.doUpdate();
restTemplate的整合配置
serverList
LoadBalancerRequestFactory
Server
这里只会拉取severList去判断一下server状态,不会真的去ping一下
@AutoConfigureBefore
BaseLoadBalancer#chooseServer
serverIntrospector
NIWSDiscoveryPing
ZoneAwareLoadBalancer
getLoadBalancer(serviceId)
spring-cloud一般配置都为xxxAutoConfiguration
getFilteredListOfServers(servers)
DiscoveryEnabledNIWSServerList
0 条评论
下一页