分布式-熔断器
现象:当服务提供者出现故障时,应该跳过服务提供者,并且快速返回
解决:给消费者设置熔断器
添加配置
feign.hystrix.enabled=true
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000
hystrix.command.default.execution.timeout.enabled=false
feign.httpclient.connection-timeout=30000
/**
* BFeign熔断降级
*/
@Component
class BFeignFallbackFactory implements FallbackFactory<BFeign> {
@Override
public BFeign create(Throwable cause) {
//打印异常
System.err.println(cause.getMessage());
//容错处理
return new BFeign() {
@Override
public String ribbon() {
return "调用service-b失败";
}
@Override
public TbDescription txlcn(Integer userId) {
return new TbDescription();
}
};
}
}
说明:BFeign是一个服务提供者的接口