spring 使用请求中的自定义布尔值重试

spring retry with custom boolean value from the request

我是 spring 注释的新手,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,如果 isRetryNeededfalse

则只需抛出一些其他异常