1

We are using Spring Boot 2.0.0.RELEASE with spring-cloud-starter-netflix-ribbon for our micro services. I set ribbon.readTimeout=1000 for slow requests and check it with our micro service setting breakpoint inside @GetMapping method without sending a response. In my test I have been waiting for 10 minutes and did not get any exception. It seems like there is no readTimeout at all.

Service configuration

ribbon:
  ReadTimeout: 1000

my-service:
  ribbon:
    eureka:
      enabled: false
    listOfServers: localhost:8080
    ReadTimeout: 1000
    ConnectTimeout: 1000

The only way a can make it work is ribbon.restclient.enabled=true. But this client is deprecated and I don't wont to use it.

veben
  • 19,637
  • 14
  • 60
  • 80

3 Answers3

4

Not all the ribbon properties are supported by spring-cloud-netflix while being used with a Spring RestTemplate. There are some ribbon properties that work, as described in the docs, but ReadTimeout is not one of them. So it does not work, but it's by desing (as per the response to this issue). However, if you are using Spring's RestTemplate, you can set it there directly, like so:

@LoadBalanced
@Bean
RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
    return restTemplateBuilder
        .setReadTimeout(2000)
        .build();
}
OlgaMaciaszek
  • 3,662
  • 1
  • 28
  • 32
  • Thank you very much indeed. I've set request timeout for RestTemplate and now it works fine. – Alexey Saltanov Nov 21 '18 at 11:18
  • @AlexeySaltanov I'm happy it was helpful. As it has solved your problem, could you please mark this answer as accepted and give it a +1? – OlgaMaciaszek Nov 21 '18 at 11:24
  • I have tried setting this timeout property in my application.yml but got the message "Unknown property 'ribbon.ReadTimeout'". This way worked perfectly! – Georgina Diaz Apr 12 '20 at 00:55
1

I think you need to configure Hystrix timeouts. Take a look at this part of the documentation : http://cloud.spring.io/spring-cloud-static/Edgware.RELEASE/single/spring-cloud.html#_hystrix_timeouts_and_ribbon_clients It could be something like that :

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 1100
ribbon:
  ConnectTimeout: 1000
  ReadTimeout: 1000
veben
  • 19,637
  • 14
  • 60
  • 80
0

We find this:

serviceA.ribbon.ReadTimeout=8000

work well with spring boot 2.1.0.RELEASE using spring cloud Finchley.SR2 and

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

However, we use ribbon via feign, in a client as so:

@FeignClient(value = "serviceA")
public interface ServiceAClient {

    @GetMapping(value = "/test")
    String getTest();
}

We then use a wiremock test to introduce a fixed delay above the read timeout to verify it is working fine.

David
  • 7,652
  • 21
  • 60
  • 98