gpt4 book ai didi

spring-boot - 为什么 spring boot 应用程序不断从配置服务中获取配置?

转载 作者:行者123 更新时间:2023-12-05 03:48:24 27 4
gpt4 key购买 nike

我正在使用 Spring Boot 和 Spring Cloud Config 构建微服务。从日志文件中,我可以看到我的一个应用程序每五分钟向配置服务发送一次配置请求,而其他应用程序则不执行相同的行为。

06:04:28.586 [serviceId:xxx-service/traceId:545d584f10da3123/spanId:545d584f10da3123/parentId:] INFO  o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment - Fetching config from server at : http://config-service
06:04:30.135 [serviceId:xxx-service/traceId:545d584f10da3123/spanId:545d584f10da3123/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.log - Located environment: name=xxxservice, profiles=[dev], label=master, version=00ed4aebcd466c88b4a7df61296652944642cdc8, state=null
06:09:30.367 [serviceId:xxx-service/traceId:519fdde3a2d8ce5a/spanId:519fdde3a2d8ce5a/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment - Fetching config from server at : http://config-service
06:09:31.928 [serviceId:xxx-service/traceId:519fdde3a2d8ce5a/spanId:519fdde3a2d8ce5a/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.log - Located environment: name=xxxservice, profiles=[dev], label=master, version=00ed4aebcd466c88b4a7df61296652944642cdc8, state=null
06:14:32.035 [serviceId:xxx-service/traceId:e32c45c3a5c3fcca/spanId:e32c45c3a5c3fcca/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment - Fetching config from server at : http://config-service
06:14:33.611 [serviceId:xxx-service/traceId:e32c45c3a5c3fcca/spanId:e32c45c3a5c3fcca/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.log - Located environment: name=xxxservice, profiles=[dev], label=master, version=00ed4aebcd466c88b4a7df61296652944642cdc8, state=null
06:19:32.033 [serviceId:xxx-service/traceId:16fc982b0638d4a6/spanId:16fc982b0638d4a6/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment - Fetching config from server at : http://config-service
06:19:33.495 [serviceId:xxx-service/traceId:16fc982b0638d4a6/spanId:16fc982b0638d4a6/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.log - Located environment: name=xxxservice, profiles=[dev], label=master, version=00ed4aebcd466c88b4a7df61296652944642cdc8, state=null
06:24:32.036 [serviceId:xxx-service/traceId:f4eae364e2624d58/spanId:f4eae364e2624d58/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment - Fetching config from server at : http://config-service
06:24:33.640 [serviceId:xxx-service/traceId:f4eae364e2624d58/spanId:f4eae364e2624d58/parentId:] INFO o.s.c.c.c.ConfigServicePropertySourceLocator.log - Located environment: name=xxxservice, profiles=[dev], label=master, version=00ed4aebcd466c88b4a7df61296652944642cdc8, state=null

我试图理解这种行为。

1 此服务的bootstrap.yml是否与其他服务不同,导致独特的行为?

不,所有服务 bootstrap.yml 似乎都是相同的结构,没有不同的配置键:

spring:
profiles:
active: dev
cloud:
config:
name: xxxservice
label: master
uri: http://config-service

2 这个服务是否试图动态和周期性地刷新它的配置?

不,为了动态刷新 spring boot 应用程序的配置,我们需要:

  • 在类读取配置上加上@RefreshScope注解
  • 调用 curl -X POST http://xx:8080/refresh 来手动触发刷新

所以不应该有周期性的自动刷新行为。

问题悬而未决,希望有人直接说明这个情况,或者指出我表述中的错误。

最佳答案

我不知道为什么您在其他服务中看不到这种情况,但我相信这种行为是由于客户端想要定期检查服务器的健康状况所致。来自 Spring Cloud Config 客户端文档:

7.8.1 Health Indicator

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

所以只要设置health.config.enabled=false,这种行为就会停止。

关于spring-boot - 为什么 spring boot 应用程序不断从配置服务中获取配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64399739/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com