Spring Cloud Consul Config over Spring Cloud Config [英] Spring Cloud Consul Config over Spring Cloud Config

查看:34
本文介绍了Spring Cloud Consul Config over Spring Cloud Config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm having a real tough time with this one. We want to use Spring Cloud Consul for service discovery and my colleges are pushing the idea to use Spring Cloud Consul Config over Spring Cloud Config, which I have already previously implemented for a related project. The thing is, Spring Cloud Config works great and has a seamless out-of-the-box version control conduit (git) for a dynamic centralized management of properties. In order to support this same functionality in Spring Cloud Consul Config it seems would require re-inventing the wheel already baked into Spring Cloud Config.

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

Does anyone have experience using both? Would it make sense to use both together? That is, have Spring Cloud Config Client pointing to a Spring Cloud Config Server for the more "static" environment properties (things that vary between dev, qa, stage, production both otherwise static) and Spring Cloud Consul Config for pure dynamic properties like service discovery?

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

Someone please correct me if I am wrong but from my understanding what I will need to do in order to support dynamic version control for "static" properties using Spring Cloud Consul Config, I would need some kind of conduit between say git and the physical "/config" directory of the running instance of each Spring Cloud Consul Config application instance :/

推荐答案

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

tl;dr: I use spring cloud config and spring cloud consul but not spring cloud consul config.

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

I did not use spring cloud consul config specifically since I am not using consul config, but I am using a spring cloud config server that register itself in consul and I have other microservices accessing the spring cloud config server through consul for service discovery. Both server and client uses spring cloud consul to register and discover the config server. And the config server and config clients both uses 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:

bootstrap.properties:

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

application.properties:

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:

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:

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:

Application.java:

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

这篇关于Spring Cloud Consul Config over Spring Cloud Config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆