Spring Cloud 消息总线 - Bus

Spring Cloud 消息总线 - Bus

3.1-bus-概述

1587799845708

• Spring Cloud Bus 是用轻量的消息中间件将分布式的节点连接起来,可以用于广播配置文件的更改或者服务的监控管理。关键的思想就是,消息总线可以为微服务做监控,也可以实现应用程序之间相通信。

• Spring Cloud Bus 可选的消息中间件包括 RabbitMQ 和 Kafka

3.2-bus-rabbitmq回顾

1587800000865

1587800012091

RabbitMQ 提供了 6 种工作模式:简单模式、work queues、Publish/Subscribe 发布与订阅模式、Routing
路由模式、Topics 主题模式、RPC 远程调用模式(远程调用,不太算 MQ;暂不作介绍)。

1587800088435

RabbitMQ Window 安装参考资料中RabbitMQ Windows 安装.md

3.3-bus-快速入门

  1. 分别在 config-server 和 config-client中引入 bus依赖:bus-amqp

            <!-- bus -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-bus-amqp</artifactId>
            </dependency>
    
  2. 分别在 config-server 和 config-client中配置 RabbitMQ

    bootstrap.yml

      #配置rabbitmq信息
      rabbitmq:
        host: localhost
        port: 5672
        username: guest
        password: guest
        virtual-host: /
    

OrderController上添加@RefreshScope注解

@RestController
@RequestMapping("/order")
@RefreshScope
public class OrderController {


    @Value("${itheima}")
    private String itheima;
    ...
    }
  1. 在config-server中设置暴露监控断点:bus-refresh

    application.yml

    # 暴露bus的刷新端点
    management:
      endpoints:
        web:
          exposure:
            include: 'bus-refresh'
    
  2. 启动测试

    curl结果中没有信息,说明成功了

    1587801187953

1587799845708

posted @ 2021-01-25 17:16  60kmph  阅读(166)  评论(0编辑  收藏  举报