In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to understand ZookeeperDiscoveryAutoConfiguration, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can gain something.
Mainly study ZookeeperDiscoveryAutoConfiguration
ZookeeperDiscoveryAutoConfiguration
SpringMurray cloudlue zookeeperMouse discoveryMouse 2.1.2.RELEASEsarsources.jarbrands, orgpickSpringframeworkAccording to cloudMookeeperlap discoveryDiscoveryAutoConfiguration.java
@ Configuration@ConditionalOnBean (ZookeeperDiscoveryClientConfiguration.Marker.class) @ ConditionalOnZookeeperDiscoveryEnabled@AutoConfigureBefore ({CommonsClientAutoConfiguration.class, NoopDiscoveryClientAutoConfiguration.class}) @ AutoConfigureAfter ({ZookeeperDiscoveryClientConfiguration.class}) public class ZookeeperDiscoveryAutoConfiguration {@ Autowired (required = false) private ZookeeperDependencies zookeeperDependencies; @ Autowired private CuratorFramework curator; @ ConditionalOnMissingBean public ZookeeperDiscoveryProperties zookeeperDiscoveryProperties (InetUtils inetUtils) {return new ZookeeperDiscoveryProperties (inetUtils) } @ Bean @ ConditionalOnMissingBean / / currently means auto-registration is false. That will change when / / ZookeeperServiceDiscovery is gone public ZookeeperDiscoveryClient zookeeperDiscoveryClient (ServiceDiscovery serviceDiscovery, ZookeeperDiscoveryProperties zookeeperDiscoveryProperties) {return new ZookeeperDiscoveryClient (serviceDiscovery, this.zookeeperDependencies, zookeeperDiscoveryProperties) } @ Bean public ZookeeperServiceWatch zookeeperServiceWatch (ZookeeperDiscoveryProperties zookeeperDiscoveryProperties) {return new ZookeeperServiceWatch (this.curator, zookeeperDiscoveryProperties);} @ Configuration @ ConditionalOnEnabledHealthIndicator ("zookeeper") @ ConditionalOnClass (Endpoint.class) protected static class ZookeeperDiscoveryHealthConfig {@ Autowired (required = false) private ZookeeperDependencies zookeeperDependencies @ Bean @ ConditionalOnMissingBean public ZookeeperDiscoveryHealthIndicator zookeeperDiscoveryHealthIndicator (CuratorFramework curatorFramework, ServiceDiscovery serviceDiscovery, ZookeeperDiscoveryProperties properties) {return new ZookeeperDiscoveryHealthIndicator (curatorFramework, serviceDiscovery) This.zookeeperDependencies, properties) }}}
ZookeeperDiscoveryAutoConfiguration registered ZookeeperDiscoveryProperties, ZookeeperDiscoveryClient, ZookeeperServiceWatch, ZookeeperDiscoveryHealthIndicator
ZookeeperDiscoveryProperties
SpringMurray cloudhouse zookeeperlap discoverycome2.1.2.RELEASEsarsources.jarshield
@ ConfigurationProperties ("spring.cloud.zookeeper.discovery") public class ZookeeperDiscoveryProperties {/ * * Default URI spec. * / public static final String DEFAULT_URI_SPEC = "{scheme}: / / {address}: {port}"; private InetUtils.HostInfo hostInfo; private boolean enabled = true; / * Root Zookeeper folder in which all instances are registered. * / private String root = "/ services"; / * The URI specification to resolve during service registration in Zookeeper. * / private String uriSpec = DEFAULT_URI_SPEC; / * * Id used to register with zookeeper. Defaults to a random UUID. * / private String instanceId; / * * Predefined host with which a service can register itself in Zookeeper. Corresponds * to the {code address} from the URI spec. * / private String instanceHost; / * * IP address to use when accessing service (must also set preferIpAddress to use). * / private String instanceIpAddress; / * * Use ip address rather than hostname during registration. * / private boolean preferIpAddress = false; / * * Port to register the service under (defaults to listening port). * / private Integer instancePort; / * * Ssl port of the registered service. * / private Integer instanceSslPort; / * * Register as a service in zookeeper. * / private boolean register = true; / * * Gets the metadata name/value pairs associated with this instance. This information * is sent to zookeeper and can be used by other instances. * / private Map metadata = new HashMap (); / * The initial status of this instance (defaults to * {@ link StatusConstants#STATUS_UP}). * / private String initialStatus = StatusConstants.STATUS_UP; / * Order of the discovery client used by `CompositeDiscoveryClient` for sorting * available clients. * / private int order = 0; / /.}
ZookeeperDiscoveryProperties defines enabled, root, uriSpec, instanceId, instanceHost, instanceIpAddress, preferIpAddress, instancePort, instanceSslPort, register, metadata, initialStatus, order properties
ZookeeperDiscoveryClient
SpringMurray cloudhouse zookeeperlap discoveryMur2.1.2.RELEASEsulce sources.jarframes to orghand springframeworkstop cloudmarket zookeeperlap discoveryscarp ZookeeperClient.java
Public class ZookeeperDiscoveryClient implements DiscoveryClient {private static final Log log = LogFactory.getLog (ZookeeperDiscoveryClient.class); private final ZookeeperDependencies zookeeperDependencies; private final ServiceDiscovery serviceDiscovery; private final ZookeeperDiscoveryProperties zookeeperDiscoveryProperties; public ZookeeperDiscoveryClient (ServiceDiscovery serviceDiscovery, ZookeeperDependencies zookeeperDependencies, ZookeeperDiscoveryProperties zookeeperDiscoveryProperties) {this.serviceDiscovery = serviceDiscovery; this.zookeeperDependencies = zookeeperDependencies This.zookeeperDiscoveryProperties = zookeeperDiscoveryProperties;} @ Override public String description () {return "Spring Cloud Zookeeper Discovery Client";} private static org.springframework.cloud.client.ServiceInstance createServiceInstance (String serviceId, ServiceInstance serviceInstance) {return new ZookeeperServiceInstance (serviceId, serviceInstance) } @ Override public List getInstances (final String serviceId) {try {if (getServiceDiscovery () = = null) {return Collections.EMPTY_LIST;} String serviceIdToQuery = getServiceIdToQuery (serviceId) Collection zkInstances = getServiceDiscovery () .queryForInstances (serviceIdToQuery); List instances = new ArrayList (); for (ServiceInstance instance: zkInstances) {instances.add (createServiceInstance (serviceIdToQuery, instance)) } return instances;} catch (KeeperException.NoNodeException e) {if (log.isDebugEnabled ()) {log.debug ("Error getting instances from zookeeper. Possibly, no service has registered. ", e);} / / this means that nothing has registered as a service yes return Collections.emptyList ();} catch (Exception exception) {rethrowRuntimeException (exception) } return new ArrayList ();} private ServiceDiscovery getServiceDiscovery () {return this.serviceDiscovery } private String getServiceIdToQuery (String serviceId) {if (this.zookeeperDependencies! = null & & this.zookeeperDependencies.hasDependencies ()) {String pathForAlias = this.zookeeperDependencies.getPathForAlias (serviceId); return pathForAlias.isEmpty ()? ServiceId: pathForAlias;} return serviceId;} @ Override public List getServices () {List services = null; if (getServiceDiscovery () = = null) {log.warn ("ServiceDiscovery is not yet ready-returning empty list of services") Return Collections.emptyList ();} try {Collection names = getServiceDiscovery () .queryForNames (); if (names = = null) {return Collections.emptyList () } services = new ArrayList (names);} catch (KeeperException.NoNodeException e) {if (log.isDebugEnabled ()) {log.debug ("Error getting services from zookeeper. Possibly, no service has registered. ", e);} / / this means that nothing has registered as a service yes return Collections.emptyList ();} catch (Exception e) {rethrowRuntimeException (e) } return services;} @ Override public int getOrder () {return this.zookeeperDiscoveryProperties.getOrder ();}}
ZookeeperDiscoveryClient implements the org.springframework.cloud.client.discovery.DiscoveryClient interface. Its getInstances uses curator's ServiceDiscovery.queryForInstances to obtain service instance information and then converts it to org.springframework.cloud.client.ServiceInstance type, while getServices uses curator's ServiceDiscovery.queryForNames to obtain service name information.
ZookeeperServiceWatch
SpringMurray cloudhouse zookeeperlap discoveryMur2.1.2.RELEASEsarsources.jarframes to orghand springframeworkstop cloudhand zookeeperlap discoveryscarp ServiceWatch.java
Public class ZookeeperServiceWatch implements ApplicationListener
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.