Home >Java >javaTutorial >Analysis of spring-cloud-ribbon principle: several core classes of ribbon
Ribbon is a client load balancer that provides great control over the behavior of HTTP and TCP clients. Feign has used Ribbon by default (reference article)
1. Let’s take a look at several core classes of ribbon
1, IClientConfig
Default implementation classDefaultClientConfigImpl
, mainly used to configure the relevant attribute configuration of the ribbon client
2, ServerListUpdater
Default implementation class PollingServerListUpdater
, mainly responsible for dynamically updating the server list
After the start method is called, a scheduled task will be started, with a delay of 1s to start execution, and it will be executed periodically every 30s time interval
Periodic time interval You can set the
. ##DynamicServerListLoadBalancerExecute the call during initialization
ServerListGet the server list
ConfigurationBasedServerList, the default is to get the server list from the configuration file, configure it like this
[ribbonClinetName].ribbon.listOfServers=xxx,xxx
ConsulServerListIntroduces the implementation class of consul for service discovery, which is mainly responsible for obtaining the server list of the registration center
Implementation, like this: [ribbonClient].ribbon.NIWSServerListClassName=Class name
Note: You can extend your own
ServerList
[ribbonClient].ribbon.NIWSServerListFilterClassName=Class name
HealthServiceServerListFilter The filtering judgment is the same
Note: You can extend your own
ServerList
[ribbonClient].ribbon .NFLoadBalancerPingClassName=Class name
7, ILoadBalancer
Load balancing master controller, default implementation classZoneAwareLoadBalancer, which starts the entire load balancing client
[ribbonClient].ribbon.NFLoadBalancerClassName=Class name
Load balancer startup sequence diagram:
During initialization, a scheduled task will be initialized first, which will be executed every 30 seconds. The cache will store all the instance lists allServerList obtained from the registration center and the instance list upServerList that have been successfully pinged. However, during load balancing The list I got is allServerList instead of upServerList. I don’t understand the meaning of this ping
Start a scheduled task to pull the service list from the registration center regularly and execute it every 30 seconds
Initialize to obtain the service list. The pulled service list is filtered by ServiceFilter and stored in the cache.
When the client initiates a call, it will Call the chooseServer method of ILoadBalancer to select an instance and return it to the caller according to the load balancing algorithm of IRule.
Related articles:
WPF 4 Ribbon Development Quick Access Toolbar )
SharePoint 2013 Hide the page’s Ribbon, menu and other non-content elements
The above is the detailed content of Analysis of spring-cloud-ribbon principle: several core classes of ribbon. For more information, please follow other related articles on the PHP Chinese website!