spring-retry - spring 使用请求中的自定义布尔值重试
问题描述
我是春季注释和春季重试的新手。下面是示例代码,我的查询是基于方法参数isRetryNeeded,我需要决定是否需要重试(这里3次)。谢谢
package com.example.retry;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
public interface BackendAdapter {
@Retryable(value = { RemoteServiceNotAvailableException.class }, maxAttempts = 3, backoff = @Backoff(delay = 1000))
public String getBackendResponse(boolean isRetryNeeded, boolean simulateretryfallback);
@Recover
public String getBackendResponseFallback(RuntimeException e);
}
解决方案
没有内置的支持。
但是,由于您的重试是有条件的,RemoteServiceNotAvailableException
只需抛出一些其他异常 if isRetryNeeded
is false
。
推荐阅读
- performance - 如何提高 Google Cloud Platform 中的 Tps?
- javascript - IdentityServer 在代码流期间应该返回什么?
- google-cloud-run - 谷歌云秘密管理器nodejs getsecret问题
- windows-xp - 使用尸检工具时如何确定Windows XP中用户帐户的登录次数和上次登录日期?
- java - 当所有字段以及 RadioButton 和 Spinner 之一在 Android Studio 中进行检查和归档时,如何启用按钮保存?
- terraform - local_file 和 provider 之间的 Terraform 依赖问题
- merge - 如何合并ical日历
- asp.net-mvc - SQL Server:在存储过程中使用临时表时的并发性
- gstreamer - 如果我添加了 udpsink 插件,为什么 gstreamer 管道无法播放
- swiftui - SwiftUI - 如何基于@ObservedObject 为每个列表视图项创建编辑视图