Summary of various component timeouts in Spring Cloud, springcloud

Source: Internet
Author: User

Summary of various component timeouts in Spring Cloud, springcloud

Preface

Spring Cloud is a complete set of microservice implementation frameworks based on Spring Boot. It provides configuration management, service discovery, circuit breaker, intelligent routing, microproxy, control bus, global lock, decision-making campaign, distributed session, and cluster status management required for microservice development. Most importantly, using it with the spring boot framework will make it very convenient for you to develop the cloud services of the microservice architecture. Spring Cloud contains many sub-frameworks. Among them, Spring Cloud Netflix is a set of frameworks, developed by Netflix and subsequently integrated into the Spring Cloud family. The main modules it provides include: service Discovery, circuit breaker and monitoring, intelligent routing, and client load balancing.

This article will introduce the timeout of various Spring Cloud components for your reference and learning. I will not talk much about it below. Let's take a look at the detailed introduction.

Ribbon timeout

Global settings:

ribbon:ReadTimeout: 60000ConnectTimeout: 60000

Local Settings:

service-id:ribbon:ReadTimeout: 1000ConnectTimeout: 1000

The service-id is the virtual host name used by Ribbon. It is generally the same as the service name registered on Eureka Server, that isspring.application.name.

Feign timeout

Starting from Spring Cloud Edgware, Feign supports attribute configuration Timeout:

feign: client: config:  feignName:  connectTimeout: 5000  readTimeout: 5000

For earlier versions, you can writefeign.Request.Options, Refer:org.springframework.cloud.netflix.feign.ribbon.FeignRibbonClientAutoConfiguration#feignRequestOptions.

RestTemplate timeout

In some cases, we may use RestTemplate, such

@Bean@LoadBalancedpublic RestTemplate restTemplate() {return new RestTemplate();}

You can set the timeout as follows:

@Bean@LoadBalancedpublic RestTemplate restTemplate() {SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();simpleClientHttpRequestFactory.setConnectTimeout(1000);simpleClientHttpRequestFactory.setReadTimeout(1000);return new RestTemplate(simpleClientHttpRequestFactory);}

Zuul timeout

Zuul's timeout is complicated because Zuul integrates Ribbon and Hystrix. The following two cases are discussed:

If the Zuul route uses Ribbon

Therefore, Zuul timeout is related to Ribbon and Hystrix. In this case, Zuul timeout can be configured as follows:

hystrix: command: default:  execution:  isolation:   thread:   timeoutInMilliseconds: 1000ribbon: ReadTimeout: 1000 ConnectTimeout: 1000

Code parsing: In this case, the filter used by Zuul Forwarding isorg.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilterIn this filter, Hystrix and Ribbon are integrated.

If the Zuul route does not use Ribbon

For example, the routing configuration of Zuul is as follows:

Zuul: routes: user-route: # In this configuration mode, user-route only gives the route a name, which can be named at will. Url: http: // localhost: 8000/# the path of the specified url path:/user/** # url.

Therefore, the Zuul timeout is only related to the following two configurations:

zuul: host: socket-timeout-millis: 10000 connect-timeout-millis: 2000

Code parsing: the URL routing method is directly configured. Ribbon or Hystrix is not used. The filter used for Zuul Forwarding isorg.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilterIn this filter, Zuul uses Apache HttpClient for forwarding.

In actual scenarios, the two routing methods may be used in combination. Therefore, we recommend that you configure all the above attributes.

Hystrix timeout

hystrix: command: default:  execution:  timeout:   enabled: true  isolation:   thread:   timeoutInMilliseconds: 1000

As shown above, the default timeout value of Hystrix is 1 second. The timeout mechanism is enabled by default. To disable Hystrix timeout, Setxxx.enabledSet to false.

Tips

If a component is used with Hystrix, we recommend that you set Hystrix timeout> timeout for other components. Otherwise, the retry feature may fail.

Summary

The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.