SpringCloud关于@FeignClient和Hystrix集成对http线程池监控问题

来源:互联网 发布:人工智能传感器概念股 编辑:程序博客网 时间:2024/06/05 15:57

      @FeignClient可以作为Http代理访问其他微服务节点,可以用apache的httpclient替换@FeignClient原生的URLConnection请求方式,以达到让http请求走Http线程池的目的。而@FeignClient和hystrix集成之后,在hystrix dashboard上可以监控到@FeignClient中接口调用情况和@FeignClient中httpclient中线程池使用状况。

下面是demo的示例:

1、@FeignClient的接口代码如下:

@FeignClient(value="service-A", fallback=ServiceClientHystrix.class)
public interface ServiceClient {
    
    @RequestMapping(method = RequestMethod.GET, value = "/add/{id}")
    String add(@PathVariable("id") Integer id);

}

2、ServiceClientHystrix.java

@Component
public class ServiceClientHystrix implements ServiceClient{
    @Override
    public String add(Integer id) {
        return "add value from ServiceClientHystrix";
    }

}

3、关于@FeignClient和hystrix集成后,Http线程池配置如下:

hystrix.threadpool.服务实例ID.参数

例如设置httpclient的线程池最大线程数量

hystrix.threadpool.service-A.coreSize=20//默认是hystrix.threadpool.default.coreSize = 10
hystrix.threadpool.service-A.maximumSize=20//默认是hystrix.threadpool.default.maximumSize = 10

启动服务后用测试用例连续调用接口测试,用hystrix dashboard监控得到下图监控效果:


去掉hystrix.threadpool.服务实例ID.参数配置后,再次用测试用例调用接口得到监控如下图:


PoolSize的大小取决于hystrix.threadpool.服务实例ID.coreSize大小设置


1 0