Hystrix use (RestTemplate)
1、引入hystrix依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
2、启动类:@EnableCircuitBreaker(@EnableHystrix均可)
3、@HystrixCommand(fallbackMethod = "sendFail")
4、fallback的请求参数和 返回参数 要和原方法一致。
commandProperties
@HystrixProperty(name = "fallback.enabled",value = "false") //默认true
execution.isolation.strategy: isolation strategy, default Thread
HystrixCommandProperties [statistical correlation, correlation fuse, semaphores related, other]
Hystrix use (Feign)
feign comes Hystrix, but the default is not open, first open Hystrix. (From Spring Cloud Dalston start, feign of Hystrix off by default, if you use feign, must be turned on)
feign:
hystrix:
enabled: true
@FeignClient(name = "service-name",fallback = SmsClientFallback.class)
public class ClientFallback implements ServerClient
@EnableFeignClients
@EnableCircuitBreaker
Capture fuse exception information
restTemplate:
In the fallback method parameters plus Throwable, obtaining Throwable
Feign:
. 1, @ FeignClient (name = "SMS--Service", fallbackFactory = SmsClientFallbackFactory.class)
2, realized FallbackFactory
Ignore the exception
Not go standby logical
1, inheritance HystrixBadRequestException
2, property configuration @HystrixCommand (fallbackMethod = "SendFail",
ignoreExceptions HystrixIgnoreException.class = {})