ribbon Source

-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------- 
Feign and hierarchy of the plant Ribbon, and they take care of their own for each service small factories, its parent plant is spring large factory, Feign is FeignContext, Ribbon is SpringClientFactory, both inherited

NamedContextFactory, and in each small plant, the reading order of highest to lowest priority profile is:

1, the configuration corresponding to the service exclusive: @FeignClient arranged last generation FeignClientSpecification, forming name-configuration [] pairs,

the Ribbon annotations can then register RibbonClientSpecification directly or through @RibbonClient @RibbonClients.

2, @ EnableFeignClient @RibbonClients and configured in the defaultConfiguration (in fact two annotations may be arranged individually corresponding to each micro-service configuration, but generally less than)

. 3, and SpringClientFactory FeignContext initialization of transmission to the parent class configuration NamedContextFactory class FeignClientsConfiguration and RibbonClientSpecification
-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- --------------------------------
Feign ribbon and the integration of local (in DefaultTargeter example) in a dynamic proxy class (FeignInvocationHandler ) initiates a request ---> MethodHandler (SynchronousMethodHandler) .invoke --- > client.execute.

The client track all the way up, first from ParseHandlersByName types of properties in SynchronousMethodHandler.Factory factory, and then further on, it is Feign.Builder the property, the default is a

new Client.Default, but FeignClientFactoryBean of getObject ---> loadBalance method, Feign will find from a small factory in LoadBalancerFeignClient and replace the default Client, this is actually a spring

in large factories, and registered by @Bean method FeignRibbonClientAutoConfiguration in spring.factories org.springframework.cloud.netflix package.

The execute method LoadBalancerFeignClient of them are listed, first get a FeignLoadBalancer with lbClient method call is CachingSpringLoadBalancerFactory create method,

CachingSpringLoadBalancerFactory also registered in FeignRibbonClientAutoConfiguration, in other words, also in large factories, is global.

FeignLoadBalancer is acquired in 3 RibbonClientSpecification registered ZoneAwareLoadBalancer, see point into executeWithLoadBalancer, LoadBalancerCommand is a wrapper class, submit RXJava is a thing.

RXJava alone Bowen speaking, not much to say here, because they do not affect the current logic, but the encapsulation of the result of the request, the server load balancing selection also involves following speaking into, acquired after the server, the request initiated by the FeignLoadBalancer execute method

which is invoked request.client (). execute, looking back request is executeWithLoadBalancer parent method AbstractLoadBalancerfAwareClient incoming request is assembled in the LoadBalancerFeignClient,

request class is a wrapper, request.client method returns LoadBalancerFeignClient the delegate property, looking back in @Bean LoadBalancerFeignClient method, we found new Client.Default, into point is found using the HttpURLConnection,

ConnectTimeout can see the default is 2 seconds, ReadTimeout is 5 seconds, the former is a long time to shake hands, which is a long time after the request is made to read the data returned from the monitor port, these two figures come from it?

Up layer, it is a parameter Client.Default.execute method, and then further on, FeignLoadBalancer execute method parameter, and this parameter to and from IClientConfig, executeWithLoadBalancer AbstractLoadBalancerAwareClient upward to the

method, the LoadBalancerFeignClient, execute method the method getClientConfig, point into see

if the default options options, acquired from the plant IClientConfig instance, to replace the original options. Here 3, RibbonClientConfiguration their way through the injection of small factories, @ bean method,

config.loadProperties ---> loadDefaultValues, two seconds and five seconds is provided, to override the default 10 and 60 seconds

if not the default, user instructions are defined, then use Request.Options user-defined in these two properties. So if you think the default timeout of five seconds a little short, micro-services in the notes corresponding feignclient the configuration class configuration points to

register a Request.Options to (the principle of which is above Route 1 covered pathway (corresponding to the small factories) in 3).
-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ----------
Following the above load balancing strategy talk, selectServer method, loadBalancerContext.getServerFromLoadBalancer, ILoadBalancer.chooseServer method

ILoadBalancer 3 is registered ZoneAwareLoadBalancer, which is the rule property in 3 ZoneAvoidanceRule, serverList attribute is 2 the DiscoveryEnabledNIWSServerList (

small factories RibbonEurekaAutoConfiguration pathway annotated @RibbonClients (defaultConfiguration = EurekaRibbonClientConfiguration.class), annotated here is the above mentioned micro-services corresponding to 2, arranged in this class,

the method returns ribbonServerList the annotated @Bean DiscoveryEnabledNIWSServerList, wherein parameters Provider <EurekaClient> eurekaClientProvider, principles and @lazy notes almost Provider,

Will be treated front doResolveDependency method returns a dynamic proxy class). Parent class constructor in DynamicServerListLoadBalancer ZoneAwareLoadBalancer, ServerListUpdater attribute assign a

PollingServerListUpdater (a timed task), then call restOfInit methods, where the timing task starts, the timing to call updateListOfServers ---> eurekaClient.getInstancesByVipAddress method ZoneAwareLoadBalancer update

the corresponding micro-services the serverList, here is a way to pay attention to ZoneAwareLoadBalancer registered 3, each micro small factory there is a corresponding service, so every micro-balancer is to know which service belongs.

However, to obtain full and incremental amount of words will get to expire services, if every time get the full amount for each service leaseInfo will take over, you can know the last time the service is registered with the registry when,

time too far description of the service can not be used. But now is get every increment can be modified clientConfig.shouldDisableDelta default value is true, always get the full amount.

Guess you like

Origin www.cnblogs.com/chuliang/p/11706681.html