- 消息总线,实现动态配置刷新,通过配置中心向MQ服务发送一个刷新指令,其他配置中心客户端接收刷新指令,执行配置刷新
bus rabbitmq binder-rabbit
2.修改09的添加依赖org.springframework.boot spring-boot-starter-amqp org.springframework.cloud spring-cloud-bus org.springframework.cloud spring-cloud-stream-binder-rabbit
actuator
3.修改09yml配置org.springframework.boot spring-boot-starter-actuator
暴露bus-refresh刷新路径
rabbitmq连接配置
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://gitee.com/pigeon01/springcloud1
search-paths: config
rabbitmq:
host: 192.168.64.140
port: 5672
username: admin
password: admin
virtual-host: /
server:
port: 6001
eureka:
client:
service-url:
defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
management:
endpoints:
web:
exposure:
include: bus-refresh
4.修改234的yml配置
- 添加rabbitmq连接
- 修改config的配置
- 提交推送到远程仓库
spring:
application:
name: item-service
rabbitmq:
host: 192.168.64.140
port: 5672
username: admin
password: admin
virtual-host: /
#item 8001 user8101 order8201
server:
port: 8001
cloud:
config:
override-none: true #防止从配置中心下载的配置,覆盖本地命令参数
eureka:
client:
service-url:
# 可以从云服务商购买不同地点的 eureka服务器
# 这里可以改成云服务商提供的地点
# 自己的服务器只能用defaultZone
defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
1.向http://localhost:6001/actuator/bus-refresh提交一个post请求
2.观察2.3.4控制台是否重新连接6001,刷新配置
有选择地可以发送至想发送的模块,使用的是主题交换机
- 如果不添加这个注 解,即使刷新到新的配置,也不会向对象重新注入新配置
添加99用户
POST http://localhost:6001/actuator/bus-refresh/user-service
6.访问新的用户数据GET http://localhost:3002/user-service/99
bootstrap.yml
ignore-interfaces: #忽略的网卡
spring:
cloud:
inetutils:
preferred-networks:
- 172.18.10..+
注册ip,不注册主机名
application.yml
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://gitee.com/pigeon01/springcloud1
search-paths: config
rabbitmq:
host: 192.168.64.140
port: 5672
username: admin
password: admin
virtual-host: /
server:
port: 6001
eureka:
client:
service-url:
defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
management:
endpoints:
web:
exposure:
include: bus-refresh
实现效果



