Spring Cloud Config Eureka-first方法无效

时间:2016-02-03 09:08:19

标签: spring spring-boot spring-cloud microservices netflix-eureka

我正在开发Spring Cloud Eureka微服务应用程序。我希望我的服务通过Eureka优先方法连接到配置服务。微服务被打包为docker容器并通过docker-compose进行部署。该申请由以下人员组成:

  1. myapp-service-registry:使用Spring Cloud Eureka实现的服务注册服务
  2. myapp-config-service:Spring Cloud配置服务服务器
  3. myapp-service-test:一个微服务示例,它应该尝试通过Eureka优先方法连接到配置服务来获取配置数据。
  4. 与配置服务的连接失败,如下所述。首先是一些配置数据:

    以下是myapp-service-registry的{​​{1}}:

    application.yml

    此处server: port: ${PORT:8761} eureka: client: registerWithEureka: false fetchRegistry: false server: waitTimeInMsWhenSyncEmpty: 0 的{​​{1}}:

    myapp-config-service

    配置服务器和客户端初始化为https://github.com/spring-cloud-samples/tests中的application.ymlserver: port: ${MYAPP_CONFIG_SERVICE_PORT:8888} spring: cloud: config: server: git: uri: ${MYAPP_CONFIG_SERVICE_GIT_URI} config: name: myapp-config-service # eureka service registry client eureka: client: serviceUrl: defaultZone: http://${SERVICE_REGISTRY_HOST}:${SERVICE_REGISTRY_PORT}/eureka/ instance: preferIpAddress: true 个样本:

    configserver-eureka的{​​{1}}是:

    eureka-first

    myapp-config-service的{​​{1}}:

    bootstrap.yml

    spring: application: name: myapp-config-service cloud: config: discovery: enabled: true 的{​​{1}}:

    myapp-service-test

    以下是application.yml(env变量在启动时被实际值替换):

    eureka:
        client:
            serviceUrl:
                defaultZone: http://${SERVICE_REGISTRY_HOST}:${SERVICE_REGISTRY_PORT}/eureka/
        instance:
            preferIpAddress: true
    

    我可以通过将浏览器连接到http://[...MACHINE-IP...]:8761/并查看Eureka仪表板来检查Eureka的工作情况。同样,我测试配置服务是否正常工作并响应http:///[...MACHINE-IP...]:8888/myapp-config-service;另一方面,使用上面的配置,myapp-service-test在启动时崩溃并带有以下日志:

    myapp-service-test

    请注意,如果我没有实现Eureka优先方法(并在服务的bootstrap.yml中直接设置spring.cloud.config.uri),服务注册到Eureka,找到配置服务器并正常工作(我可以在Eureka的仪表板中看到注册的服务,并且可以检查配置属性是否正确读取)。

1 个答案:

答案 0 :(得分:10)

您需要bootstrap.yml中的eureka serviceUrl(以及配置服务器的服务ID)。