Spring 多个存储库的云配置服务器回退

Spring Cloud Config Server fallback for multiple repositories

我们正在使用 spring 由 bitbucket 支持的云配置服务器来存储配置文件。我们在配置服务器的 application.yml 中配置了多个存储库。我们想让它在 bitbucket 宕机的情况下仍然可用。我们正在寻找一种可以缓存配置存储库的解决方案,如果 bitbucket 出现故障,它仍然可以提供不同存储库的属性。 下面是我的 application.yml

spring:
  cloud:
    config:
      server:
        git:
          uri: git@bitbucket.org:config1.git
          ignoreLocalSshSettings: true
          privateKey: ${PEM}
          repos:
            service1:
              uri: git@bitbucket.org:config2.git
              ignoreLocalSshSettings: true
              privateKey: ${PEM}
            service2:
              uri: git@bitbucket.org:config3.git
              ignoreLocalSshSettings: true
              privateKey: ${PEM}

我已经尝试设置 spring.cloud.config.server.git.basedir 但它只克隆了基本配置 repo。如果 bitbucket 挂了,我们如何让配置服务器从本地服务。

使用basedir 属性是唯一的出路。我们就是这样使用它的:

spring:
  cloud:
    config:
      server:
        git:
          uri: git@bitbucket.org:config1.git
          ignoreLocalSshSettings: true
          privateKey: ${PEM}
          basedir: /home/user/config1-repo
          repos:
            service1:
              uri: git@bitbucket.org:config2.git
              ignoreLocalSshSettings: true
              privateKey: ${PEM}
              basedir: /home/user/config2-repo
            service2:
              uri: git@bitbucket.org:config3.git
              ignoreLocalSshSettings: true
              privateKey: ${PEM}
              basedir: /home/user/config3-repo

您如何尝试重现 git 不可用并强制配置服务器从本地服务器路径获取属性的场景。我建议你创建本地路径。并使用 git-bash 在本地 repo 目录中克隆配置 repo。例如,在这种情况下,进入 /home/user/localRepo 并在那里克隆您的配置 git 存储库。确保正确克隆所有文件和文件夹。

然后尝试重现 git 不可用的场景并检查您的配置服务器 MS 是否能够从本地目录获取属性。这是后备的唯一出路。