公衆號: java樂園java
Ribbon能夠整合整合斷路器監控Hystrix Dashboard,Feign也不能少, 本篇講解一下Feign如何整合斷路器監控Hystrix Dashboard。本篇主要整合sc-eureka-client-consumer-feign-hystrix項目和sc-hystrix-dashboard項目。git
一、新建項目sc-feign-hystrix-dashboard,對應的pom.xml文件以下github
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>spring-cloud</groupId> <artifactId>sc-feign-hystrix-dashboard</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>sc-feign-hystrix-dashboard</name> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> </parent> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Finchley.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <!-- 說明是一個 eureka client --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> <version>1.4.5.RELEASE</version> </dependency> --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> <!-- <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId> <version>1.4.5.RELEASE</version> </dependency> --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> <!-- <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> <version>1.4.5.RELEASE</version> </dependency> --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies> </project>
說明:能夠看出這個pom.xml文件是sc-eureka-client-consumer-feign-hystrix項目和sc-hystrix-dashboard項目的並集。web
二、新建spring root 啓動類FeignDashboardApplication.javaspring
package sc.consumer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication @EnableEurekaClient @EnableFeignClients @EnableHystrixDashboard public class FeignDashboardApplication { public static void main(String[] args) { SpringApplication.run(FeignDashboardApplication.class, args); } }
這個啓動類的註解是sc-eureka-client-consumer-feign-hystrix項目和sc-hystrix-dashboard項目的並集
三、其餘項目文件說明以下,具體見源碼apache
四、啓動註冊中心sc-eureka-server和服務提供者sc-eureka-client-provider,並確保啓動成功maven
五、啓動sc-feign-hystrix-dashboard項目,並驗證是否啓動成功
方式一:訪問註冊中心查看sc-feign-hystrix-dashboard項目配置的服務名是否註冊成功ide
方式二:訪問儀表盤Dashboard對的地址http://127.0.0.1:5800/hystrixspring-boot
六、使用Hystrix Dashboard查看服務狀況
在下圖標註處輸入http://127.0.0.1:5800/hystrix.stream post
而後點擊Monitor Stream按鈕
七、使用postman訪問任意服務接口,以訪問獲取用戶信息接口爲例
http://127.0.0.1:5800/feign/user/getUser/3
儘可能多訪問幾回,而後查看儀表盤Bashboard監控後臺,發現以前一直處於Loading的界面發生了變化,以下圖,圖中單元具體含義能夠訪問網站
https://github.com/Netflix-Sk...
訪問http://127.0.0.1:5800/hystrix.stream也出現大量數據,這些數據就是對服務的監控數據。