iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 21
0
Software Development

.Net微服務輕旅行30天系列 第 21

Day 21: Steeltoe OSS提供的Circuit Breaker - Hystrix Netflix (1)

  • 分享至 

  • xImage
  •  

Steeltoe OSS整合了Netflix用java編寫的Circuit Breaker - Hystrix Netflix
https://github.com/Netflix/hystrix/wiki
為服務加了一層保護 提高強健度,本身還提供了精美的Dashboard
https://github.com/Netflix/Hystrix/wiki/Dashboard

Run Run Samples Run

跑Sample code之前請注意你電腦有安裝RabbitMQ, 官網沒有寫,
接下來的步驟會follow這個官方的文件
http://steeltoe.io/docs/steeltoe-circuitbreaker/#1-1-quick-start

啟動Eureka

先啟動Eureka, Eureka本身與Hystrix無關只是提供Sample code跑起來需要服務註冊與發現

git clone https://github.com/spring-cloud-samples/eureka.git
cd eureka
mvnw spring-boot:run

啟動Hystrix

接著啟動Hystrix Dashboard, 由於沒有提供mvnw所以Steeltoe OSS文件用的mvnw spring-boot:run是沒辦法跑的,直接使用jar

git clone https://github.com/spring-cloud-samples/hystrix-dashboard.git
mvn install
java -jar target/hystrix-dashboard-0.0.1.BUILD-SNAPSHOT.jar

打開 http://localhost:7979/ 會看到下面畫面
https://ithelp.ithome.com.tw/upload/images/20180109/20107867XxcNekeBFL.png

Sample code都在Samples\CircuitBreaker底下

啟動Fortune-Teller-Service

cd Samples/CircuitBreaker/src/AspDotNetCore/Fortune-Teller/Fortune-Teller-Service
dotnet restore --configfile nuget.config
dotnet run -f netcoreapp2.0  --server.urls http://*:5000

啟動Fortune-Teller-UI

SET BUILD=LOCAL or export BUILD=LOCAL
cd Samples/CircuitBreaker/src/AspDotNetCore/Fortune-Teller/Fortune-Teller-UI
dotnet restore --configfile nuget.config
dotnet run -f netcoreapp2.0  --server.urls http://*:5555

會看到連結到Hystrix Metrics connected! 就是成功了

info: Steeltoe.CircuitBreaker.Hystrix.MetricsStream.HystrixMetricsStreamPublisher[0]
      Hystrix Metrics starting
Hosting environment: Development
Content root path: C:\Users\ychu\Documents\Visual Studio 2017\Projects\Samples\CircuitBreaker\src\AspDotNetCore\FortuneTeller\Fortune-Teller-UI
Now listening on: http://*:5555
Application started. Press Ctrl+C to shut down.
info: Steeltoe.CircuitBreaker.Hystrix.MetricsStream.HystrixMetricsStreamPublisher[0]
      Hystrix Metrics connected!

打開Dashboard Monitor

打開Dashboard,在第一個欄位輸入 http://localhost:5555(服務位置)/hystrix/hystrix.stream
點Monitor Stream, 我期待我會看到
https://github.com/Netflix/Hystrix/wiki/images/dashboard-annoted-circuit-640.png

實際上我是看到....
https://ithelp.ithome.com.tw/upload/images/20180109/201078672ujHwYqNSN.png
人生總是不如想像....出現錯誤了

查log的可能性有:

  • client端接到RabbitMQ有問題

    fail: Steeltoe.CircuitBreaker.Hystrix.MetricsStream.HystrixMetricsStreamPublisher[0]
        Error sending metrics to Hystrix dashboard, metrics streaming disabled: RabbitMQ.Client.Exceptions.AlreadyClosedException: Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=404, text="NOT_FOUND - no exchange 'spring.cloud.hystrix.stream' in vhost '/'", classId=60, methodId=40, cause=
           at RabbitMQ.Client.Impl.SessionBase.Transmit(Command cmd)
           at RabbitMQ.Client.Impl.ModelBase.ModelSend(MethodBase method, ContentHeaderBase header, Byte[] body)
           at RabbitMQ.Client.Impl.ModelBase.BasicPublish(String exchange, String routingKey, Boolean mandatory, IBasicProperties basicProperties, Byte[] body)
           at Steeltoe.CircuitBreaker.Hystrix.MetricsStream.HystrixMetricsStreamPublisher.<StartMetricsPublishing>b__11_0(List`1 jsonList)
    
  • 應該要輸入的Url並非是官網所寫的http://localhost:5555/hystrix/hystrix.stream

    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
        Request starting HTTP/1.1 GET http://localhost:5555/hystrix/hystrix.stream
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
        Request finished in 16.6917ms 404
    

    所以404找不到對外的端口。

    結果猜測都是錯的,請見下篇Day22


上一篇
Day 20 Steeltoe OSS提供的Service Registry and Discovery (4)
下一篇
Day 22: Steeltoe OSS提供的Circuit Breaker - Hystrix Netflix (2)
系列文
.Net微服務輕旅行30天30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言