spring webclient: retry with backoff on specific error

前端 未结 4 1317
后悔当初
后悔当初 2021-01-12 16:07

i\'d like to retry the request 3 times after waiting 10sec when response is 5xx. but i don\'t see a method that I can use. On object

WebClient.builder()
             


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-12 17:09

    the retryWhen with Retry.anyOf and Retry.onlyIf are deprecated I assume. I found this approach useful, and it allows us to process and throw a User defined exception.

    for example :

    retryWhen(Retry.backoff(3, Duration.of(2, ChronoUnit.SECONDS))
                            .filter(error -> error instanceof UserDefinedException/AnyOtherException)
                            .onRetryExhaustedThrow((retryBackoffSpec, retrySignal) ->
                                    new UserDefinedException(retrySignal.failure().getMessage())))
    

提交回复
热议问题