In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "the use of ConsulAutoConfiguration in spring cloud". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "the use of ConsulAutoConfiguration in spring cloud".
Order
This paper mainly studies the ConsulAutoConfiguration of spring cloud.
ConsulAutoConfiguration
SpringMurphy cloudhouse consortium Murray 2.1.2.RELEASEMohamsources.jarwithorgAccording to springframeworkAccording to consulatory ConsulAutoConfiguration.java
@ Configuration@EnableConfigurationProperties@ConditionalOnConsulEnabledpublic class ConsulAutoConfiguration {@ Bean @ ConditionalOnMissingBean public ConsulProperties consulProperties () {return new ConsulProperties ();} @ Bean @ ConditionalOnMissingBean public ConsulClient consulClient (ConsulProperties consulProperties) {final int agentPort = consulProperties.getPort (); final String agentHost =! StringUtils.isEmpty (consulProperties.getScheme ())? ConsulProperties.getScheme () + ": / /" + consulProperties.getHost (): consulProperties.getHost (); if (consulProperties.getTls ()! = null) {ConsulProperties.TLSConfig tls = consulProperties.getTls () TLSConfig tlsConfig = new TLSConfig (tls.getKeyStoreInstanceType (), tls.getCertificatePath (), tls.getCertificatePassword (), tls.getKeyStorePath (), tls.getKeyStorePassword ()); return new ConsulClient (agentHost, agentPort, tlsConfig) } return new ConsulClient (agentHost, agentPort);} @ Configuration @ ConditionalOnClass (Endpoint.class) protected static class ConsulHealthConfig {@ Bean @ ConditionalOnMissingBean @ ConditionalOnEnabledEndpoint public ConsulEndpoint consulEndpoint (ConsulClient consulClient) {return new ConsulEndpoint (consulClient) } @ Bean @ ConditionalOnMissingBean @ ConditionalOnEnabledHealthIndicator ("consul") public ConsulHealthIndicator consulHealthIndicator (ConsulClient consulClient) {return new ConsulHealthIndicator (consulClient) } @ ConditionalOnClass ({Retryable.class, Aspect.class) AopAutoConfiguration.class}) @ Configuration @ EnableRetry (proxyTargetClass = true) @ Import (AopAutoConfiguration.class) @ EnableConfigurationProperties (RetryProperties.class) protected static class RetryConfiguration {@ Bean (name = "consulRetryInterceptor") @ ConditionalOnMissingBean (name = "consulRetryInterceptor") public RetryOperationsInterceptor consulRetryInterceptor (RetryProperties properties) { Return RetryInterceptorBuilder.stateless () .backOffOptions (properties.getInitialInterval () Properties.getMultiplier (), properties.getMaxInterval () .maxAttempts (properties.getMaxAttempts ()) .build () }}}
ConsulAutoConfiguration registered ConsulClient, ConsulEndpoint, ConsulHealthIndicator
ConsulEndpoint
Springhouse cloudhouse consortium house 2.1.2.RELEASUSue sources.jarUniverse orgAccording frame workbank cloudlap consulatory ConsulEndpoint.java
@ Endpoint (id = "consul") public class ConsulEndpoint {private ConsulClient consul; public ConsulEndpoint (ConsulClient consul) {this.consul = consul;} @ ReadOperation public ConsulData invoke () {ConsulData data = new ConsulData (); / / data.setKeyValues (kvClient.getKeyValueRecurse ()); Response agentServices = this.consul.getAgentServices () Data.setAgentServices (agentServices.getValue ()); Response catalogServices = this.consul .getCatalogServices (QueryParams.DEFAULT); for (String serviceId: catalogServices.getValue (). KeySet ()) {Response response = this.consul .getCatalogService (serviceId, QueryParams.DEFAULT) Data.getCatalogServices () .put (serviceId, response.getValue ());} Response catalogNodes = this.consul .getCatalogNodes (QueryParams.DEFAULT); data.setCatalogNodes (catalogNodes.getValue ()); return data } / * Represents Consul data related to catalog entries and agent servies. * / public static class ConsulData {Map catalogServices = new LinkedHashMap (); Map agentServices; List catalogNodes; public ConsulData () {} public Map getCatalogServices () {return this.catalogServices } public void setCatalogServices (Map catalogServices) {this.catalogServices = catalogServices;} public Map getAgentServices () {return this.agentServices } public void setAgentServices (Map agentServices) {this.agentServices = agentServices;} public List getCatalogNodes () {return this.catalogNodes;} public void setCatalogNodes (List catalogNodes) {this.catalogNodes = catalogNodes } @ Override public String toString () {return new ToStringCreator (this) .append ("catalogServices", this.catalogServices) .append ("agentServices") This.agentServices) .append ("catalogNodes", this.catalogNodes) .toString () }}}
ConsulEndpoint has a ReadOperation, which returns ConsulData, including agentServices, agentServices, and catalogNodes.
ConsulHealthIndicator
SpringMurphy cloudhouse consortium house 2.1.2.RELEASEMohamsources.jarwithorgAccording to springframeworkUniverse cloudlink consulthIndicator.java
Public class ConsulHealthIndicator extends AbstractHealthIndicator {private ConsulClient consul; public ConsulHealthIndicator (ConsulClient consul) {this.consul = consul;} @ Override protected void doHealthCheck (Health.Builder builder) throws Exception {final Response leaderStatus = this.consul.getStatusLeader (); final Response services = this.consul .getCatalogServices (QueryParams.DEFAULT) Builder.up () .withDetail ("leader", leaderStatus.getValue ()) .withdetail ("services", services.getValue ());}}
ConsulHealthIndicator inherits AbstractHealthIndicator, and its doHealthCheck will call ConsulClient.getStatusLeader to get leaderStatus and ConsulClient.getCatalogServices to get catalogServices information.
Summary
ConsulAutoConfiguration registered ConsulClient, ConsulEndpoint, ConsulHealthIndicator
ConsulEndpoint has a ReadOperation, which returns ConsulData, including agentServices, agentServices, and catalogNodes.
ConsulHealthIndicator inherits AbstractHealthIndicator, and its doHealthCheck will call ConsulClient.getStatusLeader to get leaderStatus and ConsulClient.getCatalogServices to get catalogServices information.
At this point, I believe you have a deeper understanding of "the use of ConsulAutoConfiguration in spring cloud". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.