從零學SpringCloud系列(五):SpringBoot2.2.5集成Hystrix Dashboard及遇到的坑

一、項目信息

SpringBboot版本:2.2.5

SpringCloud版本:Hoxton.SR

二、maven依賴

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

三、在程序啓動類上 增加 @EnableHystrixDashboard 註解,開啓hystrixDashboard 

@SpringBootApplication
@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableHystrixDashboard
public class RabbionConsumerApplication {

四、配置文件

server.port= 7070

spring.application.name=ribbon-consumer

eureka.client.serviceUrl.defaultZone= http://localhost:1111/eureka/

#在springboot 2.0版本以後需要增加此配置,否則會出現下面的錯誤
management.endpoints.web.exposure.include=*

五、訪問首頁

輸入地址:http://localhost:7070/hystrix/

當我們在輸入框當中輸入:http://localhost:7070/hystrix.stream,Title裏面輸入Hystrix,卻出現瞭如下的界面: 

頁面提示Unable to connect to Command Metric Stream。 

我們只需要在配置文件當中引入如下配置:注意最後的*一定要加上引號,不然會啓動報錯。

#management.endpoints.web.exposure.include=*
management:
    endpoints:
       web:
          exposure:
             include: "*"

我們輸入框當中輸入的不能是http://localhost:7070/hystrix.stream,而是http://localhost:8011/actuator/hystrix.stream

再次進入頁面,發現一直在顯示Loading....

這個時候,我們只需要去訪問幾次提供熔斷的方法就可以解決了,因爲現在我們還沒有訪問過熔斷的方法,系統找不到數據。

我們多訪問幾次熔斷方法,刷新儀表盤,看到如下頁面。

 

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