Spring Cloud消息总线组件之 Spring Cloud Bus

使用消息队列来实现每次修改完配置文件后,往队列里写一个消息,由spring cloud bus 提供的功能,从队列中读取消息,然后重新加载一次。

也分为客户端 和 服务端

1、服务端配置,配置中心pom中添加依赖:

<dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-bus</artifactId>
</dependency>
 <dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>

2、客户端配置

  <!--消息总线依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-bus</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

消息读写,写在config微服务中,读的配置需要在git上的配置中添加rabbitmq的配置。

注意点:

如果修改git配置中心,实现的是自定义配置而非系统级配置,那就需要在该微服务的控制层添加注解@RefreshScope 实现自定义配置的消息总线刷新。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值