(七)Spring Cloud Bus 消息总线

(七)Spring Cloud Bus 消息总线_第1张图片

Spring Cloud Bus做配置更新步骤如下:

1.提交代码触发post给Server端发送bus/refresh
2.Server端接收到请求并发送给Spring Cloud Bus
3.Spring Cloud bus接到消息并通知给其它客户端
4.其它客户端接收到通知,请求Server端获取最新配置
5.全部客户端均获取到最新的配置

在server端的代码做一些改动,来支持/actuator/bus-refresh
(1)添加依赖


    org.springframework.cloud
    spring-cloud-starter-bus-amqp

(2)application.yml

server:
  port: 8097
spring:
  application:
    name: spring-cloud-config-server
  cloud:
    config:
      server:
        git:
          uri: https://github.com/xxx/springcloud-config # git仓库的地址
          # search-paths:   # 仓库文件夹名称,多个以逗号分隔
          username:  #Git仓库用户名
          password:  #Git仓库密码
          default-label: main
  rabbitmq:
    host: 127.0.0.1
    port: 5672
    username:
    password:
management:
  endpoints:
    web:
      exposure:
        include: "*"
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

依次启动eureka,config-serve,config-client1,config-client2,修改git上的配置,访问curl -X POST http://localhost:8081/actuator/bus-refresh,可以看到两个客户端都能拿到修改后的值

你可能感兴趣的:((七)Spring Cloud Bus 消息总线)