Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to understand ServerList in Ribbon

Shulou Source: shulou.com Published: 2022-06-01 20:26:35 10月03日 Update

Today, I will talk to you about how to understand ServerList in Ribbon. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

ServerList is the object of the deposit service instance.

ServerList

Public interface ServerList {public List getInitialListOfServers (); / * * Return updated list of servers. This is called say every 30 secs * (configurable) by the Loadbalancer's Ping cycle * * / public List getUpdatedListOfServers ();}

StaticServerList

Maintain the list of services through static configuration.

Public class StaticServerList implements ServerList {private final List servers; public StaticServerList (T... Servers) {this.servers = Arrays.asList (servers);} @ Override public List getInitialListOfServers () {return servers;} @ Override public List getUpdatedListOfServers () {return servers;}}

AbstractServerList

ServerList interceptor, used by LoadBalancer.

Public abstract class AbstractServerList implements ServerList, IClientConfigAware {/ * * Get a ServerListFilter instance. It uses {@ link ClientFactory#instantiateInstanceWithClientConfig (String, IClientConfig)} * which in turn uses reflection to initialize the filter instance. * The filter class name is determined by the value of {@ link CommonClientConfigKey#NIWSServerListFilterClassName} * in the {@ link IClientConfig}. The default implementation is {@ link ZoneAffinityServerListFilter}. * / public AbstractServerListFilter getFilterImpl (IClientConfig niwsClientConfig) throws ClientException {try {String niwsServerListFilterClassName = niwsClientConfig .getProperty (CommonClientConfigKey.NIWSServerListFilterClassName, ZoneAffinityServerListFilter.class.getName ()) .toString (); AbstractServerListFilter abstractNIWSServerListFilter = (AbstractServerListFilter) ClientFactory.instantiateInstanceWithClientConfig (niwsServerListFilterClassName, niwsClientConfig) Return abstractNIWSServerListFilter;} catch (Throwable e) {throw new ClientException (ClientException.ErrorType.CONFIGURATION, "Unable to get an instance of CommonClientConfigKey.NIWSServerListFilterClassName. Configured class: "+ niwsClientConfig .getProperty (CommonClientConfigKey.NIWSServerListFilterClassName), e);}

ConfigurationBasedServerList

Through the configuration file parameter listOfservers, to achieve ServerList. Multiple are separated by commas.

Public class ConfigurationBasedServerList extends AbstractServerList {private IClientConfig clientConfig; @ Override public List getInitialListOfServers () {return getUpdatedListOfServers ();} @ Override public List getUpdatedListOfServers () {String listOfServers = clientConfig.get (CommonClientConfigKey.ListOfServers); return derive (listOfServers);} @ Override public void initWithNiwsConfig (IClientConfig clientConfig) {this.clientConfig = clientConfig;} protected List derive (String value) {List list = Lists.newArrayList () If (! Strings.isNullOrEmpty (value)) {for (Strings: value.split (",")) {list.add (new Server (s.trim ());}} return list;}}

DiscoveryEnabledNIWSServerList

Through the service discovery of Eureka, the ServerList.

Public class DiscoveryEnabledNIWSServerList extends AbstractServerList {@ Override public List getInitialListOfServers () {return obtainServersViaDiscovery ();} @ Override public List getUpdatedListOfServers () {return obtainServersViaDiscovery ();} private List obtainServersViaDiscovery () {List serverList = new ArrayList (); if (eurekaClientProvider = = null | | eurekaClientProvider.get () = = null) {logger.warn ("EurekaClient has not been initialized yet, returning an empty list") Return new ArrayList ();} EurekaClient eurekaClient = eurekaClientProvider.get (); if (vipAddresseswritten null) {for (String vipAddress: vipAddresses.split (",")) {/ / if targetRegion is null, it will be interpreted as the same region of client List listOfInstanceInfo = eurekaClient.getInstancesByVipAddress (vipAddress, isSecure, targetRegion) For (InstanceInfo ii: listOfInstanceInfo) {if (ii.getStatus (). Equals (InstanceStatus.UP)) {if (shouldUseOverridePort) {if (logger.isDebugEnabled ()) {logger.debug ("Overriding port on client name:" + clientName + "to" + overridePort) } / / copy is necessary since the InstanceInfo builder just uses the original reference, / / and we don't want to corrupt the global eureka copy of the object which may be / / used by other clients in our system InstanceInfo copy = new InstanceInfo (ii) If (isSecure) {ii = new InstanceInfo.Builder (copy) .setSecurePort (overridePort). Build ();} else {ii = new InstanceInfo.Builder (copy) .setPort (overridePort). Build () }} DiscoveryEnabledServer des = new DiscoveryEnabledServer (ii, isSecure, shouldUseIpAddr); des.setZone (DiscoveryClient.getZone (ii)); serverList.add (des) }} if (serverList.size () > 0 & & prioritizeVipAddressBasedServers) {break; / / if the current vipAddress has servers, we dont use subsequent vipAddress based servers} return serverList;}} after reading the above, do you have any further understanding of how to understand ServerList in Ribbon? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Content services configuration parameters multiple instances objects files more knowledge articles maintenance services industry information information channels commas static channels interceptors into one Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Tech Info Shulou Technology MySQL Apple