在 Spring 云配置服务器中组织大量应用程序配置

Organizing large amounts of application configuration in Spring Cloud Config Server

现在 Spring Cloud Config 已正式发布,我们正在考虑将其用作 Spring 启动应用程序的外部配置源。因为所涉及的技术对我们的组织来说太新了,所以我收到了很多关于 Cloud Config 如何在生产中工作的问题,尤其是在部署和灾难场景方面。

我想我开始了解服务器如何加载和分发配置,这让我想知道组织和部署配置的最佳方式是什么。我的第一个想法是让每个应用程序都有自己的 Git 存储库以及一个通用配置存储库。

这里的问题是我一直在误读文档。我的印象是我可以做这样的事情:

git:
   uri: ssh://git@stash:7999/scc/common-config.git
   repos:
      app-config:
         uri: ssh://git@stash:7999/scc/
         pattern: app*-config.git    

考虑到 app-config 部分会选择所有 Git 与模式匹配的存储库。当我们部署新的应用程序时,我们将重新启动服务器以获取新存储库中的配置。我没有得到的是该模式指的是指定存储库中的文件,而不是 git 文件本身。所以我真正需要做的是这样的:

git:
   uri: ssh://git@stash:7999/scc/common-config.git
   repos:
      app-foo-config:
         uri: ssh://git@stash:7999/scc/app-foo-config.git
         pattern: app-foo*    

我使用这种方法的问题是,每次我部署另一个应用程序时,除了重新启动它们之外,我还需要一个进程来更新云配置服务器的 bootstrap.yml 文件,以添加另一个应用程序的回购,像这样:

git:
   uri: ssh://git@stash:7999/scc/common-config.git
   repos:
      app-foo-config:
         uri: ssh://git@stash:7999/scc/app-foo-config.git
         pattern: app-foo*    
      app-bar-config:
         uri: ssh://git@stash:7999/scc/app-bar-config.git
         pattern: app-bar*    

这不是很理想。对我来说,看起来我必须按域将我的配置分成几个存储库,这给了我这样的东西:

git:
   uri: ssh://git@stash:7999/scc/common-config.git
   repos:
      domain-foo-config:
         uri: ssh://git@stash:7999/scc/domain-foo-config.git
         pattern: domain-foo*    
      domain-bar-config:
         uri: ssh://git@stash:7999/scc/domain-bar-config.git
         pattern: domain-bar*    
      domain-baz-config:
         uri: ssh://git@stash:7999/scc/domain-baz-config.git
         pattern: domain-baz*    

只要我能保持域的逻辑性,这应该可以防止我的配置过于失控。那么,我的问题是什么?有两个:

  1. 我的最终方法是合理的还是我遗漏了更好的方法?

  2. 文档暗示配置可以在文件夹中,这将有助于保持配置的组织性。有人运气好吗?

此外,由于您已经进入我的文本墙这么远,我认为多个回购配置的模式存在漏洞。

没有模式,服务器不会从存储库中的任何文件传递任何配置。最重要的是,虽然模式:“*”有效,但它仅适用于第一个回购。之后,无论给出什么模式,云配置服务器都无法从任何其他存储库中的任何文件加载任何配置。这包括默认回购。

Without a pattern the server doesn’t deliver any configuration from any of the files in the repo. On top of that while pattern: “*” works, it only works for first repo. After that, the Cloud Config Server cannot load any configuration from any file in any other repo no matter what pattern is given. This includes the default repo.

如果你不需要模式,你可以简单地使用

git:
   uri: ssh://git@stash:7999/scc/common-config.git

如果您需要使用带模式的回购协议,请确保您的应用程序在 bootstrap.yml 中的 spring.application.name 具有相同的模式。例如,

spring:
   application:
      name: domain-foo-app-a