hystrix监控功能
1.添加maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
2.添加注解
@EnableCircuitBreaker
3.添加@HystrixCommand
@ResponseBody
@GetMapping("/list")
@HystrixCommand(fallbackMethod="listFallBack")
public User[] list(){
System.out.println("list-->"+Thread.currentThread().getId());
User[] list = restTemplate.getForObject("http://spring-cloud-provider/user/list", User[].class);
return list;
}
public User[] listFallBack(){
System.out.println("listFallBack-->"+Thread.currentThread().getId());
return new User[]{};
}
4.验证
先从浏览器打开http://localhost:9000/user/list
注意:一定先浏览一下http://localhost:9000/user/list,否则没法打开http://localhost:9000/hystrix.stream
在打开监控页面
http://localhost:9000/hystrix.stream
浏览器打开Hystrix dashboard