Bus既可以指公共汽车,也可以指总线。

比如说git更新了配置,要如何通知到config服务?这里一般采用消息,常用的消息队列比如RabbitMQ

这种bus技术,只用在pom中加入一个depenency即可:

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-bus-amqp</artifactId>

</dependency>

当然还要设置rabbitmq内容:

rabbitmq:

host: rabbitmq的ip

username: 账号

password: 密码

port: 5672

但是这样还是不可以!查看队列信息,有两个队列啊!

微服务学习8——Spring cloud Bus自动刷新配置

再来看一下队列是怎么处理数据的:

微服务学习8——Spring cloud Bus自动刷新配置

然后再config的yml中,加入:

management:

endpoints:

web:

exposure:

include: "*"

并且在调用的类上加上@RefreshScope:

@RestController

@RequestMapping("/env")

@RefreshScope

public class EnvController {

这样,调用这个url:http://localhost:8080/actuator/bus-refresh之后就会更新配置!(是对配置中心发起)

这样就可以自动更新配置。

 

 

 

 

 

相关文章: