Spring cloud retry mechanism and retry summary of each component

Spring cloud retry mechanism configuration

First of all, the retry here is not the retry after an error is reported, but the load balancing client tries other instances after finding that the remote request instance is unreachable.

Feign retry mechanism

Feign is configured to retry through the retryer under its own package by default. The default is 5 times

Feign cancel retry

Feign request timeout setting

Retry of components in spring cloud

Recently, many children's shoes asked me how to configure the retry of spring cloud XXX components. This chapter makes a summary.

The retry mechanism in spring cloud should be said to be chaotic. Different versions have certain differences, and the implementation is not the same. Fortunately, spring cloud Camden has basically stabilized, and Dalston has made some improvements. The details are not shown for the time being.

Let's discuss it in detail.

The version used by the author is spring cloud Dalston Sr4, which is also applicable to Edgware and later versions. The previous versions of Dalston are not discussed in this paper, and you can study them by yourself.

Retry of ribbon + resttemplate

For resttemplate integrated with ribbon, for example, @ loadbalanced annotation is added to a resttemplate:

On this basis, retry can be realized by using the following configuration:

Retry of feign

Feign also has retry capability. In the early spring cloud, feign used feign Retryer. Default #default(), retry 5 times. However, feign integrates ribbon, which also has the ability to retry. At this time, it may lead to behavior confusion.

Spring cloud is aware of this problem, so it makes improvements by changing feign's retry to feign Retryer#NEVER_ Retry, if you need to use feign's retry, just use ribbon's retry configuration. Therefore, for Camden and later versions, feign retry can be configured with the following properties:

For relevant issues, please refer to: https://github.com/spring-cloud/spring-cloud-netflix/issues/467

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>