当前位置:网站首页>@Retryable @backoff @recover retry the use of annotations
@Retryable @backoff @recover retry the use of annotations
2022-07-25 02:31:00 【WuSong1999】
@Retryable Note the functions of each parameter as follows

Use scenarios :

Handle RetryableException.class abnormal , If it throws RetryableException.class abnormal (value = RetryableException.class), Then start the retry mechanism .
The maximum number of retries is 5 Time (maxAttempts = 5), The first is 100 millisecond .
Every subsequent retry is the previous 1.5 times (Backoff(delay = 100L, multiplier = 1.5))@Backoff Note the functions of each parameter as follows

Be careful :
In the use of @Retryable and @Recover When the annotation , There are several points to pay attention to :
First , You want to add maven rely on
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
And add @EnableRetry Annotation makes @Retryable and @Recover Annotations to take effect .
in addition @Retryable and @Recover The method of modification should be in the same class , And be @Retryable The marked method cannot have a return value , such Recover The method works .
Last , because @Retryable Annotations are implemented through facets , So we should avoid @Retryable The caller and callee of the annotated method are in the same class , Because it will make @Retryable Note invalid
Examples :
@ApiOperation(" Test retry ")
@PostMapping("/testRetry")
public XXFResponseResult<Void> testRetry(){
recordService.testRetry();
return new XXFResponseResult<>();
} void testRetry(); @Retryable(value = {RetryException.class},// Specifies the exception that occurred to try again
maxAttempts=3, // Retry count , Default is 3
backoff = @Backoff(value = 2000))// Delay milliseconds per retry
@Override
public void testRetry() {
log.info("retry start");
throw new RetryException("retry fail");
}
@Recover
public void recover (RetryException e) {
log.info("recovery,{}",e.getMessage());
}边栏推荐
- Inventory of well-known source code mall systems at home and abroad
- [circular array] JS method collection of circular array
- [leetcode] 2. Add two numbers - go language problem solving
- Unable to display spline in UE4 (unreal engine4) terrain editing tool
- Introduction to web security telent testing and defense
- Sword finger offer 11. rotate the minimum number of the array
- About the relationship between parent process and child process (UAC bypass idea)
- Keepalivetime=0 description of ThreadPoolExecutor
- Detailed explanation of manually writing servlet in idea
- VRRP virtual redundancy protocol configuration
猜你喜欢

I was forced to graduate by a big factory and recited the eight part essay in a two-month window. Fortunately, I went ashore, otherwise I wouldn't be able to repay the mortgage

Consul cluster deployment

A bit of knowledge - websites about scripts

"Ask the sky" is in place! Yu Jingchuan's "China Space Station" in 2013 is about to set sail in the sea of stars

ICO objects in classification
![[C language] program compilation (preprocessing)](/img/94/175a84d89b1f16987e529eb029cbbc.png)
[C language] program compilation (preprocessing)

Today in history: the kotlin language was published for the first time; The father of the IMAP agreement was born; CT imaging achieves a new breakthrough

Use SAP ui5 application to consume create and delete operations of OData in business application studio

Explorer TSSD 2019 software installation package download and installation tutorial

These 11 chrome artifacts are extremely cool to use
随机推荐
ByteDance confirmation will be self-developed chip: for internal use only; Musk: I have uploaded my brain to the cloud; Go language product head leaves | geek headline
Mgre.hdlc.ppp.chap.nat comprehensive experiment
Use Fiddler to capture apps
Example demonstration of "uncover the secrets of asp.net core 6 framework" [02]: application development based on routing, MVC and grpc
Is it necessary to increase the number of milliseconds and save several KB of memory in the program?
Gerrit statistics script
The importance of system to Philosophy Hegel
Summary and sorting of XSS (cross site script attack) related content
Why can't reading more books improve your writing?
Jedispoolconfig parameter configuration from the perspective of source code
ICO objects in classification
My creation anniversary (3rd Anniversary)
"I gave up programming and wrote a 1.3 million word hard science fiction."
"Ask the sky" is in place! Yu Jingchuan's "China Space Station" in 2013 is about to set sail in the sea of stars
Computing network, AI first, shengteng AI helps operators' Digital Transformation -- work together to win-win Computing Era
Work arrangement of generator set
How to upload files to the server
What are the basic skills of engineers? How to practice? -- Learning experience sharing "suggestions collection"
6-10 vulnerability exploitation SMTP experimental environment construction
HAC cluster is modified to stand-alone