springcloud

013--Eureka中Feign对Hystrix支持

2018-05-20  本文已影响33人  糖纸疯了

话题一:Feign使用Hystrix实现断路FallBack

    @FeignClient(name="server-provider",fallback=ConsumeFeignHystrix.class)
    public interface ConsumeFeign {
    
         @RequestMapping(value = "/simple/{id}", method = RequestMethod.GET)
         public User findById(@PathVariable("id") Long id); // 两个坑:1. @GetMapping不支持   2. @PathVariable得设置value
    }
    // 进行Hystrix的实现
    @Component//必须添加,要不然程序启动不了
    class ConsumeFeignHystrix implements ConsumeFeign{
        @Override
        public User findById(Long id) {
            User user = new User(11L, "xaioming");
            return user;
        }
    }

话题二:禁用Feign对Hystrix的支持

        @Bean
        @Scope("prototype")
        //禁用Feign对Hystrix的支持
        public Feign.Builder feignBuilder(){
            return Feign.builder();
        }
上一篇 下一篇

猜你喜欢

热点阅读