feign关闭hystrix

hystrix的熔断机制可能会导致fegin的重复请求策略无效(重复请求的超时时间必须小于hystrix的熔断时间)。所以在某些情况下可以选择关闭fegin的hystrix

一、为指定的Feign客户端禁用Hystrix

1) 创建一个Feign禁用Hystrix的禁用配置类

package com.itmuch.cloud;

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

import feign.Feign;

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

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

}

2) Feign接口类的配置

package com.itmuch.cloud;

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 即可.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值