0

我遵循了这个文档:http ://cloud.spring.io/spring-cloud-consul/1.0.x/index.html并将我的 Spring Boot 应用程序配置如下:

spring:
  cloud:
    consul:
      enabled: true
      host: consul.domain.tld
      port:  443
      discovery:
        instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
        fail-fast: false

当部署到 Cloud Foundry 时,应用可以连接到 Consul 并尝试注册,但 Consul 的“服务检查”立即失败。

阅读配置的内容,我在 Spring Boot 应用程序中得到以下实例:

list = discoveryClient.getInstances("myApp");
list.get(0) => "http://05c81764-18a4-4905-41a8-b5b8:8080"

我看到 UUID 很可能是 Cloud Foundry 生成的 instanceId。当然,该 URL 不起作用,无论是在 Cloud Foundry 中还是对于尝试定期检查服务的健康状况的外部 Consul 服务器都不起作用。

如何正确配置我的 Spring Boot 应用程序才能在 Cloud Foundry 中使用 Consul 进行服务注册?

4

1 回答 1

1

您需要设置spring.cloud.consul.discovery.hostname为 vcap 环境变量返回的值。

就像是:

spring.cloud.consul.discovery.hostname=${vcap.application.uris[0]:localhost}
spring.cloud.consul.discovery.port=80
于 2017-08-17T18:26:01.760 回答