注意:school项目依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<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>
通过postman调用school微服务
http://localhost:8088/getSchoolDetails/abcschool
修改io.spring2go.hystrixlab.schoolservice.delegate.StudentServiceDelegate
中StudentServiceDelegate
方法上的标注,依次实验各种Hystrix Command标注用法:
- 简单用法
@HystrixCommand
- 定制超时
@HystrixCommand(commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "4000") })
- 定制降级方法
@HystrixCommand(fallbackMethod = "callStudentService_Fallback")
- 定制线程池隔离策略
@HystrixCommand(fallbackMethod = "callStudentService_Fallback",
threadPoolKey = "studentServiceThreadPool",
threadPoolProperties = {
@HystrixProperty(name="coreSize", value="30"),
@HystrixProperty(name="maxQueueSize", value="10")
}
)
- 查看hystrix stream和dashboard
hystrix stream:
http://localhost:8088/hystrix.stream
hystrix dashboard
http://localhost:8088/hystrix