Hystix熔断器使用

@EnableFeignClients(basePackages = {“com.pendanaan.service”}) 在 启动main类上加

接口创建
@FeignClient(name = “account-service”, fallbackFactory = CollegeServiceFallBackFactory.class)
public interface CollegeServiceClient {}

实现类 实现 FallbackFactory
@Component
public class CollegeServiceFallBackFactory implements FallbackFactory {}

yml配置文件

hystrix:
command: #命令
VisionServiceClient#uploadStorage(StorageUploaderDto): #这里配置就是在当前client的uploadStorage方法有效
execution:
isolation:
strategy: SEMAPHORE #使用信号量模式 默认是线程池模式
semaphore:
maxConcurrentRequests: 20 #最大并发请求20直接快速返回失败 默认是 10
thread:
timeoutInMilliseconds: 20000 #超市时间 20秒

有了 hystrix之后
我们之前是 用户 -----> 服务器controller -------> service -------> dao

更改为

                 用户   ---------->B服务的 controller   -----------> A服务的 serviceClient	(可以快速返回失败   接口 ) ----通过http请求----> A服务的controller    ----------> service  ------------>  dao
发布了64 篇原创文章 · 获赞 11 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/Summer_i/article/details/99583987
今日推荐