spring-bootspring-cloudspring-cloud-netflixnetflix-ribbon

Why does using ribbonReadTimeout don't break long request with Netflix Ribbon?


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.


Solution

  • 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();
    }