一、Hystrix接口调用超时时间配置
在application.yml 中设置 hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds 来指定接口间调用的超时时间。当接口调用时超过该时间未响应则执行降级逻辑。
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 1000
二、Hystrix监控平台搭建
在使用HystrixCommand 或 HystrixObservableCommand 包裹的接口依赖被调用时,Hystrix会生成运行结果和运行指标,比如每秒请求数,成功数量等这些状态会暴露在actuator的、health的端点中。
- 1,通过Actutor获取Hystrix监控数据
步骤一、pom中添加Hystrix与actuator依赖。
<!-- 服务监控 -->
<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>
步骤二、启动类上添加@EnableCircuitBreaker 注解激活Hystrix
@SpringBootApplication
@EnableFeignClients
@EnableCircuitBreaker
public class OrderApplication {
public static void main(String[] args) {
步骤三、在配置文件中配置需要记录的端点信息
#actuator配置暴露的端点 * 表示全部。 还有 info、health、beans等
management:
endpoints:
web:
exposure:
include: '*'
步骤四、访问启动的应用ip端口+actuator/hystrix.stream
- 2,搭建Hystrix DashBoard 监控(本过程是在上一种监控方式的基础上搭建)
步骤一、添加依赖
<!-- 服务监控 -->
<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>
步骤二、启动类添加@EnableHystrixDashboard 激活Hystrix仪表盘
@SpringBootApplication
@EnableFeignClients
@EnableCircuitBreaker
/**
* 激活HystrixDashboard仪表盘
*/
@EnableHystrixDashboard
public class OrderApplication {
public static void main(String[] args) {
步骤三、打开dashboard监控首页地址(http://ip:port/hystrix),输入需要监控的页面流地址
点击监控流按钮跳转到新的界面,当有请求发生时,通过监控界面可以看到不同服务的请求结果信息,以及请求的请求数。通过不同颜色可以看到不同的请求结果处理数量(数据都为当前实时的数量展示)