如何在春季重试框架中配置延迟以首次重试
即时通讯在一个应用程序上,即IM使用Spring @Retryable执行重试操作3次(默认情况下重试计数为3)。以下是我的示例代码
@Retryable(
value= CustomException.class,
backoff = @Backoff(
delay = 5000,
multiplier = 2,
maxDelay = 20000
)
)
public void performRetry() throws CustomException {
try {
if(RetrySynchronizationManager.getContext().getRetryCount()==0) { // retry count starts from 0.
logger.info("Starting Retry attempts. Thread name {}. Giving delay of 3 seconds", Thread.currentThread().getName());
Thread.sleep(3000);
}
boolean response = service.execute(); // calling main service
// Rest of the code
} catch(Exception e) {
logger.error("Retry Count {} Error occurred {}", RetrySynchronizationManager.getContext().getRetryCount(), e.getMessage());
throw new CustomException(e.getMessage());
}
}
我的查询是,我想在第一次尝试(而不是首次重试)之前引入3秒钟的延迟,即首次调用我的主服务service.execute();
。
由于在春季重试,它立即触发了第一次尝试而不会延迟。因此,在我的代码中,在我呼叫我的主服务service.execute();
首次使用thread.sleep(3000);
IM使用retrysynchronizationManager。 getContext()。getReTryCount()
获得重试计数。因此,如果它的0含义第一次尝试,则表示第二次尝试(第一次重试呼叫),而2表示第三次尝试(第二个重试呼叫)。
还有其他方法可以让使用thread.sleep()分开延迟吗?
我有什么办法可以指定 @retryable注释中的第一次重试的延迟?
等待早期回应。
Im working on an application where im using spring @Retryable to perform retry operation for 3 times (By default retry count is 3). Below is my sample code
@Retryable(
value= CustomException.class,
backoff = @Backoff(
delay = 5000,
multiplier = 2,
maxDelay = 20000
)
)
public void performRetry() throws CustomException {
try {
if(RetrySynchronizationManager.getContext().getRetryCount()==0) { // retry count starts from 0.
logger.info("Starting Retry attempts. Thread name {}. Giving delay of 3 seconds", Thread.currentThread().getName());
Thread.sleep(3000);
}
boolean response = service.execute(); // calling main service
// Rest of the code
} catch(Exception e) {
logger.error("Retry Count {} Error occurred {}", RetrySynchronizationManager.getContext().getRetryCount(), e.getMessage());
throw new CustomException(e.getMessage());
}
}
My query is that i want to introduce a delay of 3 seconds before doing first attempt (not first retry) i.e. calling my main service service.execute();
for the first time.
Since in spring retry it immediately triggers the first attempt without any delay. So in my code before im calling my main service service.execute();
for the first time im using Thread.sleep(3000);
Im using RetrySynchronizationManager.getContext().getRetryCount()
to get retry count. So if its 0 meaning first attempt, 1 means second attempt (first retry call) and 2 means third attempt (second retry call).
Is there any other way that i can give delay apart from using thread.sleep()?
Is there any way i can specify delay for the first retry in @Retryable annotation?
Waiting for an early response.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个重试是第二个呼叫。
无法为第一个呼叫配置延迟;您必须在通话代码中这样做。
The first retry is the second call.
There is no way to configure a delay for the first call; you would have to do that in your calling code.