【问题标题】:Spring Cloud Consul Config over Spring Cloud ConfigSpring Cloud Consul Config 优于 Spring Cloud Config
【发布时间】:2016-02-18 08:34:41
【问题描述】:

我在这个问题上遇到了真正的困难。我们想使用 Spring Cloud Consul 进行服务发现,我的大学正在推动使用 Spring Cloud Consul Config 而不是 Spring Cloud Config 的想法,我之前已经为一个相关项目实现了这一点。问题是,Spring Cloud Config 运行良好,并且具有无缝的开箱即用版本控制管道 (git),用于动态集中管理属性。为了在 Spring Cloud Consul Config 中支持相同的功能,似乎需要重新发明已经融入 Spring Cloud Config 的轮子。

有人有使用这两种方法的经验吗?两者一起使用有意义吗?也就是说,让 Spring Cloud Config Client 指向 Spring Cloud Config Server 以获得更多“静态”环境属性(在 dev、qa、stage、production 之间变化的东西,否则都是静态的)和 Spring Cloud Consul Config 用于纯动态属性,如服务发现?

如果我错了,请有人纠正我,但根据我的理解,为了使用 Spring Cloud Consul Config 支持“静态”属性的动态版本控制,我需要做些什么,我需要在说 git 和每个 Spring Cloud Consul Config 应用程序实例的运行实例的物理“/config”目录:/

【问题讨论】:

  • 我有,但这是添加外部管道的示例。但是,Spencer,如果您推荐它,那么我很感兴趣,并且会更认真地研究它。
  • 我仔细研究了 git2consul。虽然这是一个轮询器配置,但与 spring 云配置服务器不同,它只在客户端发出请求时尝试从 git 中提取新更改,但这并不是什么大问题......也就是说,我目前遇到的问题是我想分发向 Consul 提交一组提交给 git 的属性文件;但是,如果我这样做,SCCC 不会像我假设的那样扩展到单个属性。我猜 SCCC 的想法是每个键/值映射到一个属性,这意味着我必须将 .properties 文件转换为单个键/值?
  • Spencer,我看到您在 3 月份添加了对将属性 files 存储为键的支持,此外还添加了与 git2Consul 的集成支持......太棒了!

标签: spring spring-cloud


【解决方案1】:

tl;dr:我使用 spring cloud config 和 spring cloud consul 但不是 spring cloud consul config。

我没有专门使用spring cloud consul config,因为我没有使用consul config,但是我使用的是spring cloud config服务器,它在consul中注册,并且我有其他微服务通过consul访问spring cloud config服务器以进行服务发现.服务器和客户端都使用 spring cloud consul 注册和发现配置服务器。并且配置服务器和配置客户端都使用spring cloud config。

这是我的设置:

Spring Cloud 配置服务器

依赖关系:

org.springframework.cloud:spring-cloud-config-server
org.springframework.cloud:spring-cloud-starter-consul-discovery
org.springframework.boot:spring-boot-starter-actuator

bootstrap.properties:

spring.application.name=config-server
spring.cloud.consul.host=CONSUL_HOSTNAME
spring.cloud.consul.port=CONSUL_PORT

application.properties:

spring.cloud.config.server.git.uri=GIT_REPO_URL
spring.cloud.config.server.git.username=GIT_REPO_USERNAME
spring.cloud.config.server.git.password=GIT_REPO_PASSWORD

Application.java:

@SpringBootApplication
@EnableConfigServer
@EnableDiscoveryClient
public class Application
{
    public static void main(String[] args)
    {
        SpringApplication.run(Application.class);
    }
}

Spring Cloud 客户端应用程序

依赖关系:

org.springframework.cloud:spring-cloud-starter-config
org.springframework.cloud:spring-cloud-starter-consul-discovery
org.springframework.boot:spring-boot-starter-web
org.springframework.boot:spring-boot-starter-actuator

bootstrap.properties:

spring.application.name=client-app-name
spring.cloud.consul.host=CONSUL_HOSTNAME
spring.cloud.consul.port=CONSUL_PORT
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server

Application.java:

@SpringBootApplication
@EnableDiscoveryClient
public class Application
{
    public static void main(String[] args)
    {
        SpringApplication.run(Application.class);
    }
}

【讨论】:

  • 感谢 Nicolas,目前无法对此进行检查,但 Spencer 在过去一年中为 SCCC 添加了一些出色的新功能,包括对 files 的支持和 git2consul 集成。我们可能更喜欢 git2consul 方法,因为我们现在正在使用类型安全的 hocon 配置文件来为我最初代表这个问题发起这个问题的项目进行分布式配置。
【解决方案2】:

据我了解,在配置管理方面,与 spring cloud config 相比,Consul(with git2Consul) 提供了跨多个数据中心的数据交换和节点故障转移的解决方案。

对于单个数据中心使用,spring cloud config(带有简单的故障转移解决方案,例如 LVS、主/从、rsync 机制等)就足够了。

对于服务发现,Consul 有健康检查机制,可以开启路由的自动切换。在spring cloud config中,需要做额外的工作来实现半自动发现。

【讨论】:

    猜你喜欢
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-24
    • 2016-09-29
    • 2016-12-11
    • 2018-12-23
    • 2018-12-17
    • 1970-01-01
    相关资源
    最近更新 更多