简体   繁体   English

使用Spring Cloud Consul配置可以共享配置吗?

[英]Shared config possible using Spring cloud consul config?

We're using Spring Cloud Consul Config 1.3-RELEASE on Java 8 for simple app helloworldclient, works as expected with bootstrap.xml ... 我们正在Java 8上使用Spring Cloud Consul Config 1.3-RELEASE来实现简单的应用helloworldclient,可与bootstrap.xml一起正常工作...

spring:
  cloud:
    consul:
      token: xxxx-xxxx-xxxx-xxxx
      discovery:
        enabled: true
        register: true
        service-name: helloworldclient-xyz123
        health-check-url: ${HEALTH_CHECK_URL}
      config:
        profile-separator: '/'
        enabled: true
        format: yaml
      host: ${CONSUL_HTTP_ADDR}
      port: 8500
  application:
    name: helloworldclient

Running the app with profile dev , this is the loaded config from /env ... 使用profile dev运行应用程序,这是从/env加载的配置。

    "consul:config/helloworldclient/dev/": {
       "product[0].sku": "BL394D",
       "product[0].quantity": 8 
    }

All that is fine, but we're not sure why the remaining consul config sections are even present, and what they're used for: 一切都很好,但是我们不确定为什么剩下的领事配置部分仍然存在,以及它们的用途是:

  "consul:config/application/dev/": {},
  "consul:config/application/": {},

This is interesting because we have a requirement for shared config such that multiple applications have a way load common, environment-specific config from consul, if possible; 这很有趣,因为我们需要共享配置,以便多个应用程序有可能从领事中加载通用的,特定于环境的配置; some questions to determine if this is a viable solution: 一些问题,以确定这是否是可行的解决方案:

Questions 问题

  • Is SCC attempting to read from those locations in addition to the application config path? 除了应用程序配置路径之外,SCC是否还在尝试从这些位置读取?
  • Is the default folder config/application configurable such that on startup the app reads from config/mysharedconfig instead? 默认文件夹config/application配置,以便在启动时,应用程序改为从config/mysharedconfig读取?
  • Is it suitable to use /config/application/dev as a shared config location where multiple applications can load common, environment-specific config? 是否将/config/application/dev用作共享配置位置,多个应用程序可以在其中共享特定于环境的通用配置?

I'm answering my own question: 我在回答自己的问题:

Based on documentation -- and some quick tests -- Consul supports shared properties via spring.cloud.consul.config.defaultContext , which by default is set to application , effectively loading config from consul:config/application , consul:config/application/dev , etc., on startup (in addition to config for the app, of course). 基于文档 -和一些快速测试spring.cloud.consul.config.defaultContext通过spring.cloud.consul.config.defaultContext支持共享属性,该属性默认设置为application ,有效地从consul:config/applicationconsul:config/application/dev加载配置consul:config/application/dev等,在启动时(当然,除了应用程序的配置外)。 And defaultContext is customizable, so we changed it to commoncfg then granted all ACL tokens permission to read from that location. 而且defaultContext是可自定义的,因此我们将其更改为commoncfg然后授予了所有ACL令牌读取该位置的权限。 You don't need to bother with ACL tokens unless you're using them, I only mention it because we use tokens and this step was necessary. 除非您正在使用ACL令牌,否则您无需操心,我只提到它是因为我们使用令牌,并且此步骤是必要的。

spring: cloud: consul: config: defaultContext: commoncfg 春天:云:领事:配置:默认上下文:commoncfg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM