Share via


教學課程:搭配 Azure Spring Apps 使用斷路器儀錶板

警告

Hystrix 不再處於使用中開發狀態,目前處於維護模式。

注意

Azure Spring Apps 是 Azure Spring Cloud 服務的新名稱。 雖然服務有新的名稱,但是您暫時還是會在某些位置看到舊的名稱。我們正在致力更新螢幕擷取畫面、影片和圖表等資產。

本文適用於: ✔️ Java ❌ C#

本文適用於: ✔️基本/標準✔️企業

本文說明如何在 Azure Spring Apps 上使用 Netflix Turbine 和 Netflix Hystrix。 Spring Cloud Netflix Turbine 廣泛使用來匯總多個 Netflix Hystrix 計量串流,以便使用 Hystrix 儀錶板在單一檢視中監視串流。

注意

Netflix Hystrix 在許多現有的 Spring 應用程式中廣泛使用,但不再處於主動式開發狀態。 如果您要開發新的專案,您應該改用 Spring Cloud 斷路器實作,例如 resilience4j 。 不同於本教學課程中顯示的渦輪機,新的 Spring Cloud 斷路器架構會將其計量數據管線的所有實作統一到 Micrometer,Azure Spring Apps 也支援此架構。 如需詳細資訊,請參閱使用微計收集 Spring Cloud Resilience4J 斷路器計量(預覽版)。

準備範例應用程式

此存放庫會派生此範例。

將範例存放庫複製到您的開發環境:

git clone https://github.com/Azure-Samples/azure-spring-apps-samples.git
cd azure-spring-apps-samples/hystrix-turbine-sample

建置本教學課程中的三個應用程式:

  • user-service:具有 /personalized/{id} 單一端點的簡單 REST 服務
  • recommendation-service:具有 /recommendations 單一端點的簡單 REST 服務,由使用者服務呼叫。
  • hystrix-turbine:用來顯示 Hystrix 數據流的 Hystrix 儀錶板服務,以及匯總來自其他服務的 Hystrix 計量數據流的渦輪機服務。
mvn clean package -D skipTests -f user-service/pom.xml
mvn clean package -D skipTests -f recommendation-service/pom.xml
mvn clean package -D skipTests -f hystrix-turbine/pom.xml

布建 Azure Spring Apps 實例

請遵循快速入門:將第一個應用程式部署至 Azure Spring Apps 一節中布建 Azure Spring Apps 一節中的步驟。

將您的應用程式部署至 Azure Spring Apps

這些應用程式不會使用 Config Server,因此不需要設定 適用於 Azure Spring Apps 的設定伺服器 。 建立和部署,如下所示:

az configure --defaults \
    group=<resource-group-name> \
    spring=<Azure-Spring-Apps-instance-name>

az spring app create --name user-service --assign-endpoint
az spring app create --name recommendation-service
az spring app create --name hystrix-turbine --assign-endpoint

az spring app deploy \
    --name user-service \
    --artifact-path user-service/target/user-service.jar
az spring app deploy \
    --name recommendation-service \
    --artifact-path recommendation-service/target/recommendation-service.jar
az spring app deploy \
    --name hystrix-turbine \
    --artifact-path hystrix-turbine/target/hystrix-turbine.jar

確認您的應用程式

所有應用程式都在執行且可探索之後,請使用瀏覽器的路徑https://<Azure-Spring-Apps-instance-name>-user-service.azuremicroservices.io/personalized/1進行存取user-service。 如果使用者服務可以存取 recommendation-service,您應該會取得下列輸出。 如果網頁無法運作,請重新整理幾次。

[{"name":"Product1","description":"Description1","detailsLink":"link1"},{"name":"Product2","description":"Description2","detailsLink":"link3"},{"name":"Product3","description":"Description3","detailsLink":"link3"}]

存取 Hystrix 儀錶板和計量數據流

使用公用端點或私人測試端點進行驗證。

使用公用端點

使用瀏覽器的路徑 https://<SERVICE-NAME>-hystrix-turbine.azuremicroservices.io/hystrix 存取 hystrix-turbine。 下圖顯示此應用程式中執行的 Hystrix 儀錶板。

顯示延遲和標題詳細數據的 Hystrix 儀錶板螢幕快照。

將渦輪機串流 URL https://<SERVICE-NAME>-hystrix-turbine.azuremicroservices.io/turbine.stream?cluster=default 複製到文字框中,然後選取 [ 監視串流]。 此動作會顯示儀錶板。 如果查看器中未顯示任何內容,請叫用 user-service 端點以產生數據流。

顯示線路和線程集區詳細數據的 Hystrix 數據流頁面螢幕快照。

注意

在生產環境中,Hystrix 儀錶板和計量數據流不應公開至因特網。

使用私人測試端點

Hystrix 計量數據流也可從 test-endpoint存取。 作為後端服務,我們沒有為 指派公用端點 recommendation-service,但我們可以在 測試端點顯示其計量 https://primary:<KEY>@<SERVICE-NAME>.test.azuremicroservices.io/recommendation-service/default/actuator/hystrix.stream

Hystrix 測試端點數據流頁面的螢幕快照。

作為 Web 應用程式,Hystrix 儀錶板應該使用 test-endpoint。 如果無法正常運作,則可能有兩個原因:第一,使用 test-endpoint 將基底 URL 從 / 變更為 /<APP-NAME>/<DEPLOYMENT-NAME>,或,第二個,Web 應用程式使用靜態資源的絕對路徑。 若要讓它正常運作 test-endpoint,您可能需要在前端檔案中手動編輯 <base>

下一步