Hystrix断路器 熔断器Hystrix的在Fegin的集成
作者:互联网
1.开启支持Hytrix
在application.yml中配置开启(这是需要增加的配置)
feign: hystrix: enabled: true #开启熔断支持 client: config: remote-service: #服务名,填写default为所有服务 connectTimeout: 3000 readTimeout: 3000 hystrix: command: default: execution: isolation: thread: timeoutInMilliseconds: 3000
2.写入类,实现回调类
在我们定义的接口中在添加
@FeignClient(name = "USER-SERVER", fallback = HystrixClientFallback.class)
实现HystrixClientFallback
需要使用
@Component,不然会注入失败
package cn.jiedada.Feign.impl; import cn.jiedada.Feign.UserFeginClient; import cn.jiedada.domain.User; import org.springframework.stereotype.Component; @Component public class HystrixClientFallback implements UserFeginClient { @Override public User getUserById(Long id) { return new User(-1l,"这是HystrixClientFallback的回调"); } }View Code
标签:Hystrix,Fegin,Component,jiedada,HystrixClientFallback,User,3000,熔断器,cn 来源: https://www.cnblogs.com/xiaoruirui/p/11928324.html