Timeout summary of components in spring cloud
preface
Spring cloud is a complete set of framework for implementing microservices based on spring boot. It provides configuration management, service discovery, circuit breaker, intelligent routing, micro agent, control bus, global lock, decision election, distributed session and cluster state management required for microservice development. Most importantly, when used with the spring boot framework, it will make it very convenient for you to develop cloud services of micro service architecture. Spring cloud contains many sub frameworks. Among them, spring cloud Netflix is one of the frameworks developed by Netflix and later incorporated into the spring cloud family. Its main modules include: service discovery, circuit breaker and monitoring, intelligent routing, client load balancing, etc.
This article will introduce the timeout related content of each component of spring cloud for your reference and learning. Let's take a look at the detailed introduction.
Ribbon timeout
Global settings:
Local settings:
Service ID is the virtual host name used by ribbon, which is generally consistent with the service name registered on Eureka server, that is, spring application. Name is consistent.
Feign timeout
Starting with spring cloud Edgware, feign supports timeout configuration using properties:
For the old version, you can write feign Request. Options, reference: org springframework. cloud. netflix. feign. ribbon. Feignribbonclientautoconfiguration #feignrequestoptions.
Timeout for resttemplate
In some cases, we may use resttemplate, such as
At this time, the timeout can be set as follows:
Zuul's timeout
Zuul's timeout is complex because zuul integrates ribbon and hystrix. The discussion is divided into two cases:
If zuul's route uses ribbon
The timeout of zuul is related to ribbon and hystrix. At this time, the timeout of zuul can be configured as follows:
Code analysis: in this case, the filter used for zuul forwarding is org springframework. cloud. netflix. zuul. filters. route. Ribbonroutingfilter, which integrates hystrix and ribbon.
If zuul's route does not use ribbon
For example, zuul's routing configuration is as follows:
Then, zuul's timeout is only related to the following two configurations:
Code analysis: directly configure URL routing. Neither ribbon nor hystrix can be used. The filter used for zuul forwarding is org springframework. cloud. netflix. zuul. filters. route. Simplehostroutingfilter, in which zuul uses Apache httpclient for forwarding.
In real scenarios, sometimes the two routing methods may be used together. Therefore, it is recommended that you configure all the above attributes.
Timeout for hystrix
As mentioned above, the default timeout of hystrix is 1 second. The timeout mechanism is enabled by default. To turn off the timeout of hystrix, set XXX Enabled is set to false.
Tips
If a component is used with hystrix, generally speaking, it is recommended that the timeout of hystrix > the timeout of other components, otherwise the retry feature may become invalid.
summary
The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.