1. 程式人生 > >(三)springcloud 消息總線-spring cloud bus

(三)springcloud 消息總線-spring cloud bus

nag framework 文件 -s exp oot int 增加 cli

RabbitMQ

1、RabbitMQ環境:略

2、每個服務都添加依賴,或者聚合工程中統一添加

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

3、配置

每個服務增加開放監控端點,和RabbitMQ鏈接參數配置

spring:
    config: 
        ...
  rabbitmq:
    port: 5672
    username: jianwei
    password: 654321
    host: localhost

eureka: 
    ...

management:
  endpoints:
    web:
      exposure:
        include: "*"

或者在配置倉庫增加公共配置:

# 全部開放監控端點
management:
  endpoints:
    web:
      exposure:
        include: "*"

# 鏈接rabbitmq
spring:
  rabbitmq:
    port: 5672
    username: jianwei
    password: 654321
    host: localhost

4、啟動服務

打印日誌:

這裏在網上看到很多個版本,還是以控制臺打印的為準

Mapped "{[/actuator/bus-env/{destination}],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v2+json || application/json]}" 
Mapped "{[/actuator/bus-env],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v2+json || application/json]}" 
Mapped "{[/actuator/bus-refresh],methods=[POST]}"  
Mapped "{[/actuator/bus-refresh/{destination}],methods=[POST]}" 

5、驗證:

啟動配置服務端和客戶端並訪問:http://localhost:4001/config/param

響應結果:config-client-example-value bus version0

修改配置文件:

value: config-client-example-value bus version1

向集中配置服務發送請求

POST /actuator/bus-refresh HTTP/1.1
Content-Length: 0
Host: localhost:8888
Content-Type: application/json

HTTP/1.1 204
Date: Mon, 22 Apr 2019 09:36:11 GMT

再次訪問:http://localhost:4001/config/param

響應結果:config-client-example-value bus version1

6、指定配置刷新:

/actuator/bus-refresh

通配符匹配刷新:

/actuator/bus-refresh?destination=serviceName:** // 觸發serviceName的所有實例

(三)springcloud 消息總線-spring cloud bus