13 Jun 2017

Spring Cloud Feign - Ribbon

Feign Ribbon Configuration

  1. FeignAutoConfiguration
    1. initialize feignContext
    2. initialize feignFeature
  2. FeignRibbonClientAutoConfiguration
    1. initialize CachingSpringLoadBalancerFactory cachingLBClientFactory which holds springClientFactory
    2. initialize LoadBalancerFeignClient feignClient which holds Client.Default which holds cachingLBClientFactory and springClientFactory

构建FeignClient注解代理对象

  1. FeignClientsRegistrar.registerFeignClient
  2. FeignClientFactoryBean.getObject
  3. FeignClientFactoryBean.feign
    1. context.getInstances(this.name, RequestInterceptor.class) (context is FeignContext)
      1. BeanFactoryUtils.beansOfTypeIncludingAncestors
  4. FeignClientFactoryBean.loadBalance
    1. FeignClientFactoryBean.getOptional
    2. FeignContext.getInstance(Client.class) (context from FeignAutoConfiguration)
    3. Feign.Builder.getClient (object from FeignRibbonClientAutoConfiguration.feignClient)
  5. Feign.target
  6. ReflectiveFeign.newInstance
  7. proxy Target.HardCodedTarget(type: @FeignClient annotation.getClassName)
  8. bind proxy handler to InvocationHandlerFactory.Default() -> ReflectiveFeign.FeignInvocationHandler -> SynchronousMethodHandler(client: step 5)

调用Feign接口

  1. call proxy: SynchronousMethodHandler.invoke
    1. SynchronousMethodHandler.targetRequest apply requestInterceptors
  2. LoadBalancerFeignClient.execute (client: LoadBalancerFeignClient -> FeignAutoConfiguration.feignContext && FeignRibbonClientAutoConfiguration.feignClient -> above step 5)
    1. cachingLBClientFactory creates FeignLoadBalancer object which holds FeignLoadBalancer under specific namespace configs
  3. FeignLoadBalancer.executeWithLoadBalancer
  4. LoadBalancerCommand.submit
    1. LoadBalancerCommand.selectServer
    2. FeignLoadBalancer.reconstructURIWithServer
    3. FeignLoadBalancer.execute
    4. Client.Default.execute

Tags:
0 comments