Spring Cloud Feign - Ribbon
13 Jun 2017
Feign Ribbon Configuration
- FeignAutoConfiguration
- initialize
feignContext
- initialize
feignFeature
- FeignRibbonClientAutoConfiguration
- initialize CachingSpringLoadBalancerFactory
cachingLBClientFactory
which holds springClientFactory
- initialize LoadBalancerFeignClient
feignClient
which holds Client.Default
which holds cachingLBClientFactory
and springClientFactory
构建FeignClient注解代理对象
- FeignClientsRegistrar.registerFeignClient
- FeignClientFactoryBean.getObject
- FeignClientFactoryBean.feign
- context.getInstances(this.name, RequestInterceptor.class) (context is
FeignContext
)
- BeanFactoryUtils.beansOfTypeIncludingAncestors
- FeignClientFactoryBean.loadBalance
- FeignClientFactoryBean.getOptional
- FeignContext.getInstance(Client.class) (context from
FeignAutoConfiguration
)
- Feign.Builder.getClient (object from
FeignRibbonClientAutoConfiguration.feignClient
)
- Feign.target
- ReflectiveFeign.newInstance
- proxy Target.HardCodedTarget(type:
@FeignClient
annotation.getClassName)
- bind proxy handler to InvocationHandlerFactory.Default() -> ReflectiveFeign.FeignInvocationHandler -> SynchronousMethodHandler(client: step 5)
调用Feign接口
- call proxy: SynchronousMethodHandler.invoke
- SynchronousMethodHandler.targetRequest apply requestInterceptors
- LoadBalancerFeignClient.execute (client: LoadBalancerFeignClient -> FeignAutoConfiguration.feignContext && FeignRibbonClientAutoConfiguration.feignClient -> above step 5)
cachingLBClientFactory
creates FeignLoadBalancer
object which holds FeignLoadBalancer
under specific namespace configs
- FeignLoadBalancer.executeWithLoadBalancer
- LoadBalancerCommand.submit
- LoadBalancerCommand.selectServer
- FeignLoadBalancer.reconstructURIWithServer
- FeignLoadBalancer.execute
- Client.Default.execute
comments powered by