Spring Cloud Config
发布日期:2021-05-09 04:58:04 浏览次数:17 分类:博客文章

本文共 2233 字,大约阅读时间需要 7 分钟。

1.config服务端配置

1.1 引入依赖 

org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-zookeeper-discovery
commons-logging
commons-logging

1.2 配置项application.yml

spring:  cloud:    zookeeper:      connect-string: 192.168.220.128:2181    config:      server:        git:          uri: https://gitee.com/lm970585581/cloud-config          username: lm970585581          password: *****   #密码

1.3 启动类配置

@EnableConfigServer 启用服务配置

测试说明: 

/{label}/{name}-{profiles}.yml

/{name}-{profiles}.yml
name git的文件名称不包括后缀
profiles 环境
label 分支(branch)

 

2、客户配置:provider应用

2.1 引入依赖

org.springframework.cloud
spring-cloud-config-client

2.2 配置项bootstrap.yml

spring:  cloud:    zookeeper:      connect-string: 192.168.220.128:2181    config:      discovery:        enabled: true        service-id: config #配置服务项目名      profile: dev  application:    name: provider

Spring Cloud Bus 手动实现刷配置(不重启项目情况下)

1.安装RabbitMQ 

详见:https://www.cnblogs.com/lm970585581/p/9873391.html

2.配置端引入依赖 

org.springframework.cloud
spring-cloud-starter-bus-amqp

3.配置端配置application.yml

spring:       rabbitmq:        port: 5672        host: 192.168.220.128        username: test        password: rootmanagement:  endpoints:    web:      exposure:        include: '*'  # 开启所有配置url

4.在controller上启用读取刷新数据注解@RefreshScope 

此时,当git上的配置修改后,配置应用的内容会同步修改

客户端应用的配置需要手动使用Post方式刷新,即可同步修改,无需重启服务,格式如下:地址是配置应用的地址

http://localhost:8080/actuator/bus-refresh

Spring Cloud Bus 实现自动刷配置(不重启项目情况下)+WebHooks 

加入依赖

org.springframework.cloud
spring-cloud-config-monitor

想办法把自己机器变为服务器,可以使用netaap 

在gitee里面配置webhook

通过/monitor 接口回调目标服务对应的服务 

注意:自动刷新方式有BUG存在,可能会失败,等官方修复吧!

 

 

具体实例详见:https://gitee.com/lm970585581/cloud-config

码云上的配置信息

 

上一篇:Spring Cloud Zuul(服务网关)
下一篇:安装rabbitMQ

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年03月24日 02时26分30秒