【问题标题】:How does Spring Cloud Config download remote configurations for a service?Spring Cloud Config 如何为服务下载远程配置?
【发布时间】:2015-10-28 23:40:52
【问题描述】:

几天前我在 GitHub 上找到了这个关于 spring-cloud 的example

我在使配置服务示例正常工作时遇到了一些问题。我不知道如何正确使用config-microservice

in this blog,它说你的微服务应用程序的配置应该存储在环境中而不是项目中。

但我不知道该怎么做。我不知道其中一个微服务,例如 movie-microservice Spring Boot 应用程序是如何从 config-service 获取配置文件的。

【问题讨论】:

标签: spring-boot spring-cloud microservices


【解决方案1】:

好问题。

首先,确保spring-cloud-starter-config 位于要使用配置服务远程配置的应用程序的类路径中。

http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_client_side_usage

了解配置服务是否正确地为应用程序提供环境配置的最佳方法是启用运行状况检查。

在您的配置服务配置中,确保为您的一个应用程序启用以下功能。我为movie 服务添加了健康检查,标签为master(表示使用我的git 存储库的主分支)。

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/kbastani/spring-boot-microservice-config
        health:
          repositories:
            movie:
              label: master 

现在我需要确保的是,我的 git 存储库有一个可用于我的应用程序的配置,其名称为 movie。此配置的名称可能是movie.{properties|yml}。我选择使用 yaml:https://github.com/kbastani/spring-boot-microservice-config/blob/master/movie.yml

现在,在您启动配置服务后,您可以运行健康检查以查看远程存储库是否正在使用。

$ curl http://localhost:8888/health

这将返回以下响应:

{
  "status" : "UP",
  "configServer" : {
    "status" : "UP",
    "repositories" : [ {
      "sources" : [ "https://github.com/kbastani/spring-boot-microservice-config/movie.yml", "https://github.com/kbastani/spring-boot-microservice-config/application.yml" ],
      "name" : "movie",
      "profiles" : [ "default" ],
      "label" : "master"
    } ]
  },
  "discoveryComposite" : {
    "description" : "Spring Cloud Eureka Discovery Client",
    "status" : "UP",
    "discoveryClient" : {
      "description" : "Spring Cloud Eureka Discovery Client",
      "status" : "UP",
      "services" : [ "configserver" ]
    }
  },
  "diskSpace" : {
    "status" : "UP",
    "total" : 498954403840,
    "free" : 445484142592,
    "threshold" : 10485760
  },
  "hystrix" : {
    "status" : "UP"
  }
}

现在在电影服务中,确保在bootstrap.yml中设置了以下配置。

spring:
  application:
    name: movie
  profiles:
    active: default
  cloud:
    config:
      uri: http://localhost:8888
    failFast: true

现在启动您的电影服务,首先确保配置服务正在运行并且在http://localhost:8888 可用,远程配置将用于指定的配置文件。

【讨论】:

  • 很详细,很想你!解决我的问题!
猜你喜欢
  • 2019-02-28
  • 1970-01-01
  • 2019-08-11
  • 2015-07-13
  • 2020-07-09
  • 1970-01-01
  • 2016-11-26
  • 2018-02-23
  • 2016-06-26
相关资源
最近更新 更多