Today I will share with feign the timeout and retry configuration of 061dcf9cc2ae8a.

time out

feign:
  client:
    config:
      default:
        connectTimeout: 1000
        readTimeout: 1000

The following points need to be noted:

1. The connection timeout (connectTimeout) and the read timeout (readTimeout) are configured at the same time to take effect.

2. The timeout unit is milliseconds.

3. The timeout can be defined separately according to the service name.

For example, the provider-get service provides a query interface, and the timeout period can be set shorter:

feign:
  client:
    config:
      provider-get:
        connectTimeout: 1000
        readTimeout: 6000

However, the provider-post service provides a data processing interface, and the timeout period can be set longer:

feign:
  client:
    config:
      provider-post:
        connectTimeout: 1000
        readTimeout: 20000

Retry

Implement feign.Retryer interface

public class MyRetryer implements Retryer {
    @Override
    public void continueOrPropagate(RetryableException e) {
        throw e;
    }

    @Override
    public Retryer clone() {
        return new Default(100, TimeUnit.SECONDS.toMillis(1), 5);
    }
}

Understanding of three parameters:

  • period: period, retry interval time
  • maxPeriod: the maximum period, the retry interval gradually increases according to certain rules, but cannot exceed the maximum period
  • maxAttempts: maximum number of attempts, number of retries

After that, we can configure:

feign:
  client:
    config:
      default:
        retryer: com.fengwenyi.springclouddemo.demospringcloudfeignsentinel.consumerservice.MyRetryer

Hope today's sharing can help you in your work.


冯文议
183 声望20 粉丝

软件开发工程师,专注于程序设计与开发。