SpringCloud Config: Fetching config from server at

出现场景

使用 SpringCloud Config 配置中心时,客户端每间隔5分钟会输出如下日志:

2020-11-28 18:19:59,541 INFO http-nio-8051-exec-9 (ConfigServicePropertySourceLocator.java:82)- Fetching config from server at: http://10.10.19.150:8011/
2020-11-28 18:19:59,896 INFO http-nio-8051-exec-9 (ConfigServicePropertySourceLocator.java:96)- Located environment: name=vau-trade-schedule, profiles=[prod], label=master, version=dae019860c62b88cfebe14d0a1c530591daa6f71, state=null

情况分析

通过官网查找到如下介绍:

Health Indicator

The Config Client supplies a Spring Boot Health Indicator that attempts to load configuration from the Config Server. The health indicator can be disabled by setting health.config.enabled=false. The response is also cached for performance reasons. The default cache time to live is 5 minutes. To change that value, set the health.config.time-to-live property (in milliseconds).

解释说明:由于 Config 客户端提供一个Spring引导运行状况指示器,默认5分钟进行一次状态检查。同时给出禁用的配置方式:health.config.enabled=false

查看源码:ConfigClientHealthProperties.java 文件中 timeToLive 属性确实默认是5分钟。

@ConfigurationProperties("health.config")
public class ConfigClientHealthProperties {
	/**
	 * Flag to indicate that the config server health indicator should be installed.
	 */
	boolean enabled;

	/**
	 * Time to live for cached result, in milliseconds. Default 300000 (5 min).
	 */
	private long timeToLive = 60 * 5 * 1000;

	public boolean isEnabled() {
		return this.enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public long getTimeToLive() {
		return timeToLive;
	}

	public void setTimeToLive(long timeToLive) {
		this.timeToLive = timeToLive;
	}

解决:在 bootstrap.yml 或 配置中心里的配置文件里配置即可。

health:
  config:
    enabled: false

我的项目配置方式:在项目里有 bootstrap.yml,这里面配置了应用名、使用环境、配置中心要拉取配置的文件名、环境、分支等信息;再就是 Eureka 服务地址及相关信息。由于我们的项目是多个品牌、多个环境、一套代码的方式,很多属性都是动态配置,部分代码如下:

spring:
  application:
    name: schedule
  profiles:
    active: dev
  cloud:
    config:
      name: ${proj}-trade-${spring.application.name}
      profile: ${spring.profiles.active}
      label: master
      discovery:
        enabled: true
        service-id: config

health:
  config:
    enabled: false

---
spring:
  profiles: dev

eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:8001/eureka/
  instance:
    instance-id: ${instanceId:${spring.application.name}-01}
    prefer-ip-address: true

---
spring:
  profiles: test

......

---
spring:
  profiles: prod

......

在 gitLab 的配置文件中具体再配置项目中需要的 MySQL、Redis、RabbitMQ 等等信息即可,那些基础的使用就不在此赘述。

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值