首页  

Hystrix实例     所属分类 springcloud 浏览量 132
两种用法
RestTemplate + Hystrix
feign + Hystrix

org.springframework.cloud
spring-cloud-starter-netflix-hystrix


RestTemplate @HystrixCommand(fallbackMethod = "error") @Service public class HelloService { @Resource RestTemplate eurekaRestTemplate; @HystrixCommand(fallbackMethod = "error") public String hello(String name) { Map map = new HashMap<>(); map.put("name", name); return eurekaRestTemplate.getForObject("http://provider/fegin/hello2",String.class,map); } public String error(String name) { return "HelloService.hello fallback"; } }
feign.hystrix.enabled=true @FeignClient(name = "provider",fallback=HelloFallback.class) public interface FeginHello public class HelloFallback implements FeginHello @Bean public HelloFallback helloFallback() { return new HelloFallback(); }
/hello2?name=cat /fegin/hello2?name=dyyx /fegin/hello3?name=dyyx 不启动 eureka 和 provider 触发 fallback
完整代码 https://gitee.com/dyyx/springcloud/tree/master/hystrix

上一篇     下一篇
Feign Ribbon Hystrix

eureka工作原理简介

Eureka源码要点

SpringMVC @ControllerAdvice 注解

springboot读取配置的几种方式

feign ribbon 独立使用例子