简体   繁体   English

设置connectTimeout和readTimeout后,RestTemplate不超时

[英]RestTemplate not timing out after setting connectTimeout and readTimeout

I have spring boot infrastructure with few microservices. 我有一些微服务的Spring Boot基础架构。 They communicating pretty well between each other. 他们彼此之间的交流很好。 One of the microservices have some third party calls, calling some third party services through http. 其中一个微服务有一些第三方调用,它们通过http调用了一些第三方服务。 I have defined my own RestTemplate and in the init() method I am setting connectTimeout and readTimeout. 我定义了自己的RestTemplate,并在init()方法中设置了connectTimeout和readTimeout。 From the stack traces I see that my rest template is used. 从堆栈跟踪中,我看到使用了我的rest模板。

  @PostConstruct
  public void init() {

    HttpComponentsClientHttpRequestFactory requestFactory =
        new HttpComponentsClientHttpRequestFactory();
    requestFactory.setConnectTimeout(connectTimeout);
    requestFactory.setReadTimeout(readTimeout);
    this.restTemplate = new RestTemplate(requestFactory);
  }

The problem is that some of the requests are handing for few minutes and no exceptions are thrown. 问题在于某些请求正在处理几分钟,并且不会引发任何异常。 (my timeouts are much less - about 5-10 seconds) What may be the cause? (我的超时时间要少得多-大约5-10秒)可能是什么原因? Any ideas? 有任何想法吗?

Missing the call to setConnectionRequestTimeout(...); 缺少对setConnectionRequestTimeout(...)的调用;

HttpComponentsClientHttpRequestFactory requestFactory =
        new HttpComponentsClientHttpRequestFactory();
requestFactory.setConnectTimeout(connectTimeout);
requestFactory.setReadTimeout(readTimeout);
requestFactory.setConnectionRequestTimeout(...);
this.restTemplate = new RestTemplate(requestFactory);

Spring RestTemplate timeout Spring RestTemplate超时

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM