Spring Cloud Config 集成 Spring Cloud Bus 同步远程配置

软件版本:

Spring Boot - 2.1.3.RELEASE

Spring Cloud - Greenwich.SR1

 

Spring Cloud Config Server 端

Spring Config Server 端依赖:

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-config-server</artifactId>
</dependency>

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

 

bootstrap.properties 配置文件配置 :

spring.application.name=config-server
server.port=8000

# 这里我使用了 Spring Cloud Config 支持的 JDBC Backend 配置项存储方式 
# 该配置文件中省略了 JDBC 的配置
spring.cloud.config.server.jdbc.sql=select `key` , `value` from config_properties where application = ? and profile = ? and label = ?


spring.rabbitmq.addresses=localhost:5672


# 关键, 开启对应的端点 
management.endpoints.web.exposure.include=bus-refresh,bus-env

 

Spring Cloud Bus 官方文档说明: 

Spring Cloud Bus 关于刷新配置信息端点

Spring Cloud Bus 刷新配置信息端点类: org.springframework.cloud.bus.endpoint.RefreshBusEndpoint

1b7b5cb93642a20729b0cd79fcb7e0530bb.jpg

当配置发生变更后请求 Config Server 端的刷新配置端点 : http://host:port/actuator/bus-refresh/    , 请求方法必须是 POST ,Content-Type : application/json 。这样 Config Server 会将内存中的 Environment 中存储的配置信息与外部存储中的配置信息进行比对 , 将发生变化的信息同步到内存中,同时通过 Spring Cloud Bus 将变化的配置信息以消息的方式发送到消息中间件中。Config Client 接收到该消息后就会将变化的配置项进行更新。

 

Spring Cloud Config Client 端

Spring Config Client 端依赖:

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-config-client</artifactId>
</dependency>

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-bus-amqp</artifactId>
 </dependency>

 

bootstrap.properties 配置文件配置 :

spring.application.name=demo-service

spring.cloud.config.uri=http://localhost:8000

spring.rabbitmq.addresses=localhost:5672

spring.cloud.config.fail-fast=true

 

转载于:https://my.oschina.net/j4love/blog/3031641

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值