Steeltoe OSS整合了Netflix用java編寫的Circuit Breaker - Hystrix Netflix
https://github.com/Netflix/hystrix/wiki
為服務加了一層保護 提高強健度,本身還提供了精美的Dashboard
https://github.com/Netflix/Hystrix/wiki/Dashboard
跑Sample code之前請注意你電腦有安裝RabbitMQ, 官網沒有寫,
接下來的步驟會follow這個官方的文件
http://steeltoe.io/docs/steeltoe-circuitbreaker/#1-1-quick-start
先啟動Eureka, Eureka本身與Hystrix無關只是提供Sample code跑起來需要服務註冊與發現
git clone https://github.com/spring-cloud-samples/eureka.git
cd eureka
mvnw spring-boot:run
接著啟動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/ 會看到下面畫面
Sample code都在Samples\CircuitBreaker底下
cd Samples/CircuitBreaker/src/AspDotNetCore/Fortune-Teller/Fortune-Teller-Service
dotnet restore --configfile nuget.config
dotnet run -f netcoreapp2.0 --server.urls http://*:5000
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,在第一個欄位輸入 http://localhost:5555(服務位置)/hystrix/hystrix.stream
點Monitor Stream, 我期待我會看到
實際上我是看到....
人生總是不如想像....出現錯誤了
查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