Biswajit
Biswajit

Reputation: 323

How to set timeout value for Spring Boot Configuration server

I have a simple setup for with with spring boot ConfigServer and a client service which is calling the ConfigServer to get the configuration prop file details from GIT.

My Config server is working properly and I am able to get the prop file form GIT. But when I am trying to run the consumer server which will get the details from ConfigServer server I am getting one error... Error is as follows ...

Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available

localhost:8888 is the URL for my configServer , which I able to call directly from browser , but as I have a big prop file , its taking some time to retrieve it from GIT.

Configuration at configServer (application.properties)

spring.application.name=config-server
server.port=8888
spring.cloud.config.server.git.uri=https://github.com/shibajiJava/MicroServiceDemo
spring.cloud.config.server.bootstrap=true

Configuration at Consumer Service (bootstrap.properties)

spring.application.name=configuration-service
spring.cloud.config.uri=http://localhost:8888
spring.cloud.config.server.bootstrap=true

Is there any thing to specify timeOut value at consumer end ? Thanks in advance...

Upvotes: 3

Views: 10590

Answers (2)

srini
srini

Reputation: 564

As a part of the Spring Config Client Documentation there are 2 properties available for configuring timeouts.

If you want to configure timeout thresholds:

Read timeouts can be configured by using the property spring.cloud.config.request-read-timeout.

Connection timeouts can be configured by using the property spring.cloud.config.request-connect-timeout.

Source

Upvotes: 0

user10367961
user10367961

Reputation:

Config server side:

  • Try setting spring.cloud.config.server.git.timeout to the desired value.
  • Try setting server.connection-timeout to the desired values.

Config client side:

I am not aware of any property which could do the job. You might have to override the default RestTemplate that does the request. In order to do so, create a RestTemplate with the desired timeout and inject it instead of the default one (my best guess would be with the right @Qualifier and @Primary on top of that, but you should check the sources and confirm that is indeed how the default template is injected).

@Configuration
public class ConsumerConfig {

    @Bean
    @Primary
    @Qualifier("rightQualifierHere")
    public RestTemplate configRestTemplate() {
        return new RestTemplateBuilder()
               .setReadTimeout(readTimeout)
               .setConnectTimeout(connectionTimeout)
               .build();
    }

}

Documentation:

Upvotes: 3

Related Questions