Hystrix状态监控使用方法

一、Hystrix状态查看

Hystrix状态可以通过/health接口查看,需要在yml文件中加入如下配置,指定显示全部信息:

management:
  security:
    enabled: false

二、测试

1、启动注册中心、movie、user项目;

2、访问 /movie/findById?userId=1,得到对应结果;

3、访问 /health 接口,得到如下结果:

{
	"description": "Composite Discovery Client",
	"status": "UP",
	"hystrix": {
		"status": "UP"
	}
  	...
}

Hystrix的状态为UP,表示一切正常,断路器是关闭状态。

4、挂掉 user项目;

5、访问 /movie/findById?userId=1,得到缺省结果;

6、访问 /health 接口,得到的结果和上次访问结果相同,Hystrix的状态依然为UP。这是因为失败率还没有达到阈值(默认5秒内20次失败)。

7、快速访问 /movie/findById?userId=1 后,再次访问 /health,得到结果:

{
	"description": "Composite Discovery Client",
	"status": "UP",
	"hystrix": {
		"status": "CIRCUIT_OPEN",
		"openCircuitBreakers": ["MovieController::findById"]
	}
  ...
}

Hystrix状态改变,表示断路器已打开