电光石火-穿越时空电光石火-穿越时空


feign关闭hystrix

一、为指定的Feign客户端禁用Hystrix
1) 创建一个Feign禁用Hystrix的禁用配置类

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

import feign.Feign;

/**
 * 为Feign禁用Hystrix功能
 */
@Configuration
public class FeignDisableHystrixConfiguration {

    @Bean
    @Scope("prototype") 
    public Feign.Builder feignBuilder() {
        return Feign.builder();
    }

}

2) Feign接口类的配置

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;

@FeignClient(name="cloud-service", configuration = FeignDisableHystrixConfiguration.class)   // 服务端提供者的name,这样cloud-service这个服务将不会受到hystrix保护
public interface UserFeignClient {

    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public User findById(@PathVariable("id") Long id); 

}

二、全局禁用Hystrix
只需要在yml文件中配置, feign.hystrix.enabled = false 即可.

本博客所有文章如无特别注明均为原创。作者:似水的流年
版权所有:《电光石火-穿越时空》 => feign关闭hystrix
本文地址:http://www.ilkhome.cn/index.php/archives/421/
欢迎转载!复制或转载请以超链接形式注明,文章为 似水的流年 原创,并注明原文地址 feign关闭hystrix,谢谢。

评论