赞
踩
当服务之间出现多级嵌套调用时 其中某些服务调用超时或者发生异常时,会导致整个调用链报错,无法提供正常的服务。所以Hystrix出现,它的触发机制是当某个服务调用超时或异常时,会返回一个符合预期,可处理的备选响应(fallback)来保证整个调用链正常,提供正常的服务。
<!--hystrix-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
public class PaymentHystrixMain8001
{
public static void main(String[] args) {
SpringApplication.run(PaymentHystrixMain8001.class, args);
}
}
@HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHandler",commandProperties = {
@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="5000")
})
public String paymentInfo_TimeOut(Integer id)
{
//int age = 10/0;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。