Feign禁用Hystrix

1、完全禁用Hystrix
配置yml文件feign.hystrix.enabled=false

2、部分禁用Hystrix
2.1、FeignNoHystrixConfigure.java——编写Feign客户端配置类,重写feignBuilder方法

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import feign.Feign;
import feign.Retryer;

//此配置类为了关闭特定Feign客户端的Hystrix支持
//注意:不要和服务启动类放在同一目录或子级目录下
@Configuration
public class FeignNoHystrixConfigure {

    // FeignClientsConfiguration 的默认配置如下
    // Decoder feignDecoder: ResponseEntityDecoder (which wraps a SpringDecoder)
    // Encoder feignEncoder: SpringEncoder
    // Logger feignLogger: Slf4jLogger
    // Contract feignContract: SpringMvcContract Feign.Builder
    // feignBuilder: HystrixFeign.Builder Client
    // feignClient: if Ribbon is enabled it is a LoadBalancerFeignClient, otherwise the default feign client is used.
    
    @Bean
    @Scope("prototype")
    public Feign.Builder feignBuilder(Retryer retryer) {
        return Feign.builder();
    }
    

}

 

2.2、TestClient4.java——配置部分禁用Hystrix

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.mimaxueyuan.config.FeignNoHystrixConfigure;

//关闭Hystrix(会导致所有的mima-cloud-producer都关闭,不管其它配置是否开启也会关闭,这是个坑要注意下)
@FeignClient(value="mima-cloud-producer",configuration=FeignNoHystrixConfigure.class)
public interface TestClient4 {
     
    @RequestMapping(value="/get/{id}",method=RequestMethod.GET)
    public String get(@PathVariable("id") String id);
    
}

 

posted on 2018-12-29 15:14  Ruthless  阅读(3176)  评论(0编辑  收藏  举报