springcloud(10)-斷路器監控
阿新 • • 發佈:2020-11-18
1.建立hystrix-dashboard子專案
2.新增pom.xml包
<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> <parent> <groupId>com.zhangdemo</groupId> <artifactId>springcloud</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>productServiceHystrixDashboard</artifactId> <dependencies> <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.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <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> </dependencies> </project>
3.ProductServiceHystrixDashboardApplication
@SpringBootApplication @EnableHystrixDashboard public class ProductServiceHystrixDashboardApplication { public static void main(String[] args) { int port = 8020; if(!NetUtil.isUsableLocalPort(port)) { System.err.printf("埠%d被佔用了,無法啟動%n", port ); System.exit(1); } new SpringApplicationBuilder(ProductServiceHystrixDashboardApplication.class).properties("server.port=" + port).run(args); } }
4.配置檔案修改:
spring:
application:
name: hystrix-dashboard
5.ProductViewServiceFeignApplication增加 @EnableCircuitBreaker註解
6.AccessViewService類進行訪問:
public class AccessViewService { public static void main(String[] args) { while(true) { ThreadUtil.sleep(1000); try { String html= HttpUtil.get("http://127.0.0.1:8012/products"); System.out.println("html length:" + html.length()); } catch(Exception e) { System.err.println(e.getMessage()); } } } }
7.測試
(1開啟http://localhost:8020/hystrix
(2輸入: http://localhost:8012/actuator/hystrix.stream
(3點選[Monitor Stream]
(4看到如下頁面