参考文章:https://blog.csdn.net/trisonlu123/article/details/80100031
一、体验Hystrix-Dashboard
在consumer基础上进行更改
1、增加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2、修改Main类
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
@EnableCircuitBreaker
public class ConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class, args);
}
}
3、案例
启动server,producer,consumer
访问http://localhost:8003/hystrix
点击Monitor Stream
具体看效果可以访问下接口,看下监控效果,再停掉producer服务,再访问下接口,再看监控效果
具体监控描述如下图
二、体验Turbine
1、Hystrix-dashboard-turbine
①依赖配置
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-turbine</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-hystrix-dashboard</artifactId>
</dependency>
</dependencies>
②application.properties
spring.application.name=hystrix-dashboard-turbine
server.port=8003
turbine.appConfig=node01,node02
turbine.aggregator.clusterConfig= default
turbine.clusterNameExpression= new String("default")
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
③Main类
@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class DashboardApplication {
public static void main(String[] args) {
SpringApplication.run(DashboardApplication.class, args);
}
}
2、consumer-node1,由consumer修改而来
application.properties
spring.application.name=node01
server.port=8001
feign.hystrix.enabled=true
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
3、consumer-node2,由consumer修改而来
①application.properties
spring.application.name=node02
server.port=8002
feign.hystrix.enabled=true
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
②DemoRemote.java
@FeignClient(name = "spring-cloud-producer2", fallback = DemoRemoteHystrix.class)
public interface DemoRemote {
@RequestMapping(value = "/demo")
public String demo2(@RequestParam(value = "message") String message);
}
同时修改DemoRemoteHystrix.java和DemoController.java
4、案例
同时启动服务、consumer-node1、consumer-node2、hystrix-dashboard-turbine
①访问http://localhost:8000/,发现三个注册方
②访问http://localhost:8003/turbine.stream
发现监控一直存在,不断的调出:ping
③访问http://localhost:8003/hystrix
点击Monitor Stream
发现同时监控了两个consumer