Current location - Health Preservation Learning Network - Slimming men and women - Lose weight for springbok
Lose weight for springbok
In practical work, reprocessing is a very common scene, such as:

These errors may be caused by network fluctuation, and it will be successful to wait and reprocess them. Generally speaking, try/catch, while loop and other grammars are used for reprocessing, but this method lacks uniformity, is not very convenient, and requires a lot of code.

However, spring-retry can gracefully implement the reprocessing function through comments without invading the original business logic code.

Spring-Retry of Spring series is another practical module, which can help us to handle the retry of any specific operation in a standard way. In spring-retry, all configurations are based on simple comments.

I won't introduce the basics of Spring Boot. I recommend this practical tutorial:/javastacks/spring-boot-best-practice.

Let's briefly explain the meaning of several parameters in the comments:

What happens when the number of retries runs out and still fails?

When the number of retries runs out, RetryOperations can pass control to another callback, namely RecoveryCallback. Spring-Retry also provides @Recover annotation for @Retryable to retry the processing method after failure. If you don't need a callback method, you can simply not write a callback method. This has the effect that after the number of retries, if it still doesn't meet the business judgment, an exception will be thrown.

As you can see, the pass-through parameter is written in Exception e, which is the joint code of the callback (we throw this Exception e notice to trigger this callback method if the number of retries runs out or fails).

For the method of @Recover annotation, it is important to pay special attention to:

This paper briefly introduces the use of Retryable in Springboot, which is mainly applicable to scenarios and matters needing attention, and is still very useful when retrying is needed.