10 訊息匯流排Bus
阿新 • • 發佈:2021-12-05
匯流排Bus
SpringCloud Bus動態重新整理全域性廣播
根據 3355 新建一個 3366
利用訊息匯流排觸發一個服務端 ConfigServer的/bus/refresh端點,而重新整理所有客戶端的配置:
圖二的架構顯然更加適合,圖一不適合的原因如下:
給服務端3344新增訊息匯流排支援
pom新增:
<!--新增訊息匯流排RabbitMQ的支援--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency>
yml新增:
rabbitmq:
host: 10.211.55.17 #本機寫localhost,伺服器的寫伺服器地址
port: 5672 #客戶端和RabbitMQ進行通訊的埠
username: guest #預設也是guest
password: guest #預設也是guest
#RabbitMQ相關配置
management:
endpoints: #暴露bus重新整理配置的端點
web:
exposure:
include: 'bus-refresh'
給客戶端3355和3366新增訊息匯流排支援
pom新增:
<!--新增訊息匯流排RabbitMQ的支援-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
yml新增:
rabbitmq: host: 10.211.55.17 #本機寫localhost,伺服器的寫伺服器地址 port: 5672 #客戶端和RabbitMQ進行通訊的埠 username: guest #預設也是guest password: guest #預設也是guest
測試
啟動7001,3344,3355,3366。
修改GitHub上檔案的版本號。
在終端輸入:curl -X POST "http://localhost:3344/actuator/bus-refresh"
在瀏覽器輸入http://localhost:3355/configInfo,http://localhost:3366/configInfo
SpringCloud Bus動態重新整理定點通知
- 修改GitHub的檔案版本號。
- 在終端輸入:
curl -X POST "http://localhost:3344/actuator/bus-refresh/config-client:3355"
多加了服務名:埠號即可定點通知。