91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

spring cloud中ConsulAutoConfiguration的用法

發布時間:2021-07-02 16:39:07 來源:億速云 閱讀:221 作者:chen 欄目:大數據

本篇內容主要講解“spring cloud中ConsulAutoConfiguration的用法”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“spring cloud中ConsulAutoConfiguration的用法”吧!

本文主要研究一下spring cloud的ConsulAutoConfiguration

ConsulAutoConfiguration

spring-cloud-consul-core-2.1.2.RELEASE-sources.jar!/org/springframework/cloud/consul/ConsulAutoConfiguration.java

@Configuration
@EnableConfigurationProperties
@ConditionalOnConsulEnabled
public 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注冊了ConsulClient、ConsulEndpoint、ConsulHealthIndicator

ConsulEndpoint

spring-cloud-consul-core-2.1.2.RELEASE-sources.jar!/org/springframework/cloud/consul/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<Map<String, Service>> agentServices = this.consul.getAgentServices();
		data.setAgentServices(agentServices.getValue());

		Response<Map<String, List<String>>> catalogServices = this.consul
				.getCatalogServices(QueryParams.DEFAULT);

		for (String serviceId : catalogServices.getValue().keySet()) {
			Response<List<CatalogService>> response = this.consul
					.getCatalogService(serviceId, QueryParams.DEFAULT);
			data.getCatalogServices().put(serviceId, response.getValue());
		}

		Response<List<Node>> 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<String, List<CatalogService>> catalogServices = new LinkedHashMap<>();

		Map<String, Service> agentServices;

		List<Node> catalogNodes;

		public ConsulData() {
		}

		public Map<String, List<CatalogService>> getCatalogServices() {
			return this.catalogServices;
		}

		public void setCatalogServices(
				Map<String, List<CatalogService>> catalogServices) {
			this.catalogServices = catalogServices;
		}

		public Map<String, Service> getAgentServices() {
			return this.agentServices;
		}

		public void setAgentServices(Map<String, Service> agentServices) {
			this.agentServices = agentServices;
		}

		public List<Node> getCatalogNodes() {
			return this.catalogNodes;
		}

		public void setCatalogNodes(List<Node> 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有個ReadOperation,返回的是ConsulData,包含了agentServices、agentServices、catalogNodes

ConsulHealthIndicator

spring-cloud-consul-core-2.1.2.RELEASE-sources.jar!/org/springframework/cloud/consul/ConsulHealthIndicator.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<String> leaderStatus = this.consul.getStatusLeader();
		final Response<Map<String, List<String>>> services = this.consul
				.getCatalogServices(QueryParams.DEFAULT);
		builder.up().withDetail("leader", leaderStatus.getValue()).withDetail("services",
				services.getValue());
	}

}
  • ConsulHealthIndicator繼承了AbstractHealthIndicator,其doHealthCheck會調用ConsulClient.getStatusLeader獲取leaderStatus,以及ConsulClient.getCatalogServices獲取catalogServices信息

小結

  • ConsulAutoConfiguration注冊了ConsulClient、ConsulEndpoint、ConsulHealthIndicator

  • ConsulEndpoint有個ReadOperation,返回的是ConsulData,包含了agentServices、agentServices、catalogNodes

  • ConsulHealthIndicator繼承了AbstractHealthIndicator,其doHealthCheck會調用ConsulClient.getStatusLeader獲取leaderStatus,以及ConsulClient.getCatalogServices獲取catalogServices信息

到此,相信大家對“spring cloud中ConsulAutoConfiguration的用法”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

哈密市| 寿光市| 辽宁省| 涞源县| 博客| 青龙| 永州市| 北安市| 塘沽区| 台南市| 将乐县| 丰宁| 巩义市| 四子王旗| 宁陵县| 华阴市| 察哈| 司法| 阿拉善盟| 芦山县| 锡林郭勒盟| 鸡东县| 新野县| 连州市| 方城县| 临沂市| 日照市| 车致| 华亭县| 南开区| 黄平县| 梧州市| 安义县| 晋中市| 娱乐| 呈贡县| 乌兰察布市| 延长县| 望城县| 高尔夫| 正蓝旗|