ribbon的源码解析
https://blog.csdn.net/alex_xfboy/article/details/88166216
ribbon总结:
1.LoadBalanceAutoConfiguration
LoadBalance接口--》loadBalanceClient.execute()执行的时候会调用loadBalanceInterception拦截resttemplate
2.spring-cloud-netflex-ribbon的spring.factories下配置RibbonAutoConfiguration
3.RibbonAutoConfiguration注册一个bean,bean的名字叫:SpringClientFactory
4.springClientFactory中会有ribbonClientConfiguration.
ribbonClientConfiguration会有IRule,IPing,IloadBalance等接口
Feign的总结
1.feignAutoConfiguration会生成bean:FeignContext
2.@enableFeignClient会自动扫描待有@feignClient的bean,然后通过feignContext注入一个bean,该bean的类型是:FeignFactoryBean.
3.实例化的时候会通过feignContext生产一个feign
feignClient.execute()--->SynchronousMethodHandler处理(为hystrix或者sentinel做处理)--->loadBalanceClient.execute--->restemplate.post
4.1 RibbonAutoConfiguration
为了生成loadBalanceClient
4.2 SpringClientFactory
为了生成loadBalanceClient需要SpringClientFactory
4.3 RibbonClientConfiguration
SpringClientFactory需要RibbonClientConfiguration,RibbonClientConfiguration有loadBalance,IRule,IPing等接口
4.4 LoadBalancerFeignClient
带有负载的feignClient
4.5 FeignLoadBalancer
feign的负载均衡器
4.6 LoadBalancerInterceptor
负载均衡拦截器,拦截restemplate
loadbalanceAutoConfiguration ribbonAutoConfiguration RibbonClientConfiguration
LoadBalancerInterceptor---> loadbalanceClient--->springClientFactory------->IRule,IloadBalance
LoadBalancerInterceptor需要loadbalanceClient注入
feignRibbonAutoConfiguration
注入了LoadBalancerFeignClient,cachingLBClientFactory两个bean
LoadBalancerFeignClient---> cachingLBClientFactory
---> springClientFactory