SpringCloud学习笔记(八、SpringCloud Bus)

目录:

  • 什么是bus消息总栈
  • 如何使用bus消息总栈

什么是bus消息总栈

SpringCloud Bus使用轻量的消息代理连接分布式系统的各个节点,可以用于系统状态变更时的广播(如配置变更)或其它管理指令。

如何使用bus消息总栈

见https://github.com/mrjdrs/springcloud-integration.git

需要做的事:通过改变GitHub配置达到不启动应用程序的前提下刷新配置

1、在config-server、zuul服务加入bus-amqp依赖

1 <dependency>
2     <groupId>org.springframework.cloud</groupId>
3     <artifactId>spring-cloud-starter-bus-amqp</artifactId>
4 </dependency>

2、config-server增加properties配置

1 spring.rabbitmq.host=localhost
2 spring.rabbitmq.port=5672
3 spring.rabbitmq.username=guest
4 spring.rabbitmq.password=guest
5 
6 management.security.enabled=false
7 endpoints.trace.enabled=false

3、引入配置的类上加上@RefreshScope注解

4、修改配置后通过调用接口刷新配置

)刷新应用:http://localhost:port/bus/refresh

)刷新指定应用:http://localhost:port/bus/refresh/destination=config-server:**

原文地址:https://www.cnblogs.com/bzfsdr/p/11707784.html