spring cloud bus

在MQ上會創建一個 springCloudBus 的 exchange

每個服務都會創建一個 springCloudBus.anonymous.xxx 的隊列(queue)
--springCloudBus.anonymous.Bp0n_077SIaJXXZFzGS_hQ

每個queue都會綁定exchange,routingKey 爲: #
 -- 意思是接受所有的消息
----------------------


當調用配置刷新時,調用:
POST http://localhost:8081/config/actuator/bus-refresh

會發送一條消息到MQ:
exchange: springCloudBus ,routingKey : springCloudBus

消息內容大概這樣:

{"type":"RefreshRemoteApplicationEvent","timestamp":1540780323493,"originService":"config:8081:978efb4c523dc1553ec6df9f86e8574a","destinationService":"customers:9000:**","id":"5cf7d445-0fdb-4666-8017-a4cbbf55f064"}

每個服務(Queue)都會收到該信息,然後每一個都會發送一個確認消息:

{"type":"AckRemoteApplicationEvent","timestamp":1540780484680,"originService":"gateway:8084:5a04db0104b673cb01e9961467796631","destinationService":"**","id":"bbfb9bf2-7cff-4928-9c4f-1d192b04de8c","ackId":"4e320d18-2a58-41e6-aecd-98e0a66faae3","ackDestinationService":"**","event":"org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent"}

這種模式依賴於客戶端的消息過濾,如果某個服務的消息量較大,會拖垮其它服務
所以這種模式應該用於配置等一些通用的通道,其它業務消息事件等採用另外一套,不要混合到一起

@StreamListener 註解需要包含在 @Configuration 類中才會被掃描到

引入 bus 會導致  ClasspathLoggingApplicationListener 被觸發兩次
配置中心也會拉取兩次,開啓debug,就可以從日誌看出來
官方說是正常現象,目前也沒發現異常狀況

https://stackoverflow.com/questions/48406527/spring-cloud-config-bus-calls-twice-to-the-config-server-when-the-binder-is-cr
https://github.com/spring-cloud/spring-cloud-stream/issues/1188

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章