[英]Can a Retry be configured to retry on null?
我只是从resilience4j开始,想知道是否可以设置重试以对空结果进行重试。 这是一个例子:
Retry retry = Retry.ofDefaults("retry");
Retry.decorateSupplier(retry, () -> (String) null).get();
assertThat(retry.getMetrics().getNumberOfSuccessfulCallsWithoutRetryAttempt()).isEqualTo(0);
这失败,因为返回null是可以的。 是否可以将重试配置为null。
使用您自己的retryOnResultPredicate
创建一个自定义RetryConfig
,如果result
为null
,则返回true
:
RetryConfig customConfig = RetryConfig.custom()
.retryOnResult(response -> response == null)
.build();
然后在创建Retry
实例时将其用作配置参数:
Retry retry = Retry.of("retry", customConfig);
Retry.decorateSupplier(retry, () -> (String) null).get();
assertThat(retry.getMetrics().getNumberOfSuccessfulCallsWithoutRetryAttempt()).isEqualTo(0);
有关更多示例,另请参见resilience4j文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.