Spring Discovery First Bootstrap 找不到 ConfigServer

标签 spring spring-boot spring-cloud netflix-eureka spring-cloud-config

目前,我正在使用 Discovery First 运行 Spring Boot 服务。 一个接一个地启动服务效果很好,但我在通过 docker-compose 一次启动所有服务时遇到问题。

发现第一个 Bootstrap 似乎没有按我的预期工作。我假设该服务将停止/重试,直到他从配置服务接收到配置,该配置是通过 eureka 发现的。但目前它会尝试解析一次配置,然后服务将立即启动 - 无论是否已引入配置。

服务 Bootstrap 如下所示:

spring:
  application:
    name: my-service
  cloud:
    config:
      fail-fast: false
      discovery:
        enabled: true
        service-id: configserver
      retry:
        initialInterval: 2000
        multiplier: 1.5
        maxInterval: 60000
        maxAttempts: 10

server:
  port: ${APPLICATION_PORT:16000}
eureka:
  client:
    serviceUrl:
      defaultZone: http://${EUREKA_HOSTNAME:localhost}:15000/eureka/

Eureka 配置如下:

spring:
  application:
    name: manager
server:
  port: 15000
eureka:
  client:
    registerWithEureka: true
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${EUREKA_HOSTNAME:localhost}:15000/eureka/

最后但并非最不重要的 - configserver 配置如下所示:

spring:
  application:
    name: configserver
  cloud:
    config:
      fail-fast: true
server:
  port: 15001
eureka:
  client:
    serviceUrl:
      defaultZone: http://${EUREKA_HOSTNAME:localhost}:15000/eureka/

有谁可以在这里给点建议吗?

最佳答案

我发现了这个问题:

实际上我发现我们这边有两个问题。第一个是没有合适的租约续订间隔。客户端刚刚重试使用缓存的服务接收配置。 由于缓存的服务不包含配置服务,因此他无法接收正确的配置。

第二个问题是没有等待足够的时间。这已通过提高 maxAttempts 来解决。因此配置和发现服务确实有足够的时间来启动。

客户端配置现在如下所示:

spring:
  application:
    name: service
  cloud:
    config:
      fail-fast: true
      discovery:
        enabled: true
        service-id: CONFIGSERVER
      retry:
        initialInterval: 2000
        multiplier: 1.5
        maxInterval: 60000
        maxAttempts: 100

server:
  port: ${APPLICATION_PORT:16000}
eureka:
  instance:
    lease-renewal-interval-in-seconds: 10
  client:
    fetch-registry: true
    serviceUrl:
      defaultZone: http://${EUREKA_HOSTNAME:localhost}:15000/eureka/

关于Spring Discovery First Bootstrap 找不到 ConfigServer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54670804/

相关文章:

spring - 是否有提供者不可知的方式来获取 Spring 框架中的最新缓存统计信息?

spring - 为什么Gretty慢?

java - 在 URL 中附加特殊字符

java - 在嵌入式 tomcat 中以 ROOT 身​​份部署

java - spring-data-neo4j 中的数据建模

spring-boot - 执行器/指标端点中的 Hystrix 指标 [spring-boot 2.0]

java - Flyway自动生成迁移SQL

spring-boot - 在 Spring WebFlux 中实现 Spring Cloud Sleuth 的 TracingWebFillter

spring-cloud - 如何在本地GIT存储库而不是GitHub上使用Spring Cloud Config?

java - 'opentracing: spring: web: ignoreAutoConfiguredSkipPatterns: true' 是做什么的?