我想使用WebClientfrom spring webflux 执行以下操作:
- 称呼
endpoint1 - 如果它失败并出现预期错误,那么
- 打电话
endpoint2和 - 只重试
endpoint1一次
- 打电话
我已经做到了这一点:
webclient.get()
.uri("/endpoint1")
.retrieve()
.bodyToFlux(MyBody.class)
.retry(error -> {
if (error == expectedError) {
webclient.get()
.uri("/endpoint2")
.retrieve().block();
return true;
} else {
false;
});
请求时我无法阻止,endpoint2因为我会收到以下错误:(block()/blockFirst()/blockLast() are blocking, which is not supported in thread我也不想阻止)。
也许我应该使用retryWhen,但我不确定如何使用它。