Spring Cloud 追蹤Bus Events

2023-11-30 15:09 更新

可以通過設(shè)置spring.cloud.bus.trace.enabled=true來跟蹤Bus事件(RemoteApplicationEvent的子類)。如果這樣做,Spring Boot TraceRepository(如果存在)將顯示發(fā)送的每個事件以及每個服務(wù)實例的所有確認。以下示例來自/trace端點:

{
  "timestamp": "2015-11-26T10:24:44.411+0000",
  "info": {
    "signal": "spring.cloud.bus.ack",
    "type": "RefreshRemoteApplicationEvent",
    "id": "c4d374b7-58ea-4928-a312-31984def293b",
    "origin": "stores:8081",
    "destination": "*:**"
  }
  },
  {
  "timestamp": "2015-11-26T10:24:41.864+0000",
  "info": {
    "signal": "spring.cloud.bus.sent",
    "type": "RefreshRemoteApplicationEvent",
    "id": "c4d374b7-58ea-4928-a312-31984def293b",
    "origin": "customers:9000",
    "destination": "*:**"
  }
  },
  {
  "timestamp": "2015-11-26T10:24:41.862+0000",
  "info": {
    "signal": "spring.cloud.bus.ack",
    "type": "RefreshRemoteApplicationEvent",
    "id": "c4d374b7-58ea-4928-a312-31984def293b",
    "origin": "customers:9000",
    "destination": "*:**"
  }
}

前面的跡線顯示RefreshRemoteApplicationEventcustomers:9000發(fā)送,廣播到所有服務(wù),并由customers:9000stores:8081接收(確認)。

要自己處理確認信號,您可以為應(yīng)用程序中的AckRemoteApplicationEventSentApplicationEvent類型添加一個@EventListener(并啟用跟蹤)。或者,您可以點擊TraceRepository并從那里挖掘數(shù)據(jù)。

 任何Bus應(yīng)用程序都可以跟蹤acks。但是,有時,在中央服務(wù)中執(zhí)行此操作很有用,該服務(wù)可以對數(shù)據(jù)進行更復雜的查詢,或?qū)⑵滢D(zhuǎn)發(fā)給專門的跟蹤服務(wù)。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號