From 140da0a89eaf5e72462503f9e27290bf10803462 Mon Sep 17 00:00:00 2001 From: Wendy Hu Date: Wed, 23 Aug 2023 09:58:14 -0400 Subject: [PATCH 1/2] feat(synapse-client-rest): adding retry method to reactive rest client --- .../rest/client/BaseReactiveRestClient.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/client/synapse-client-rest/src/main/java/io/americanexpress/synapse/client/rest/client/BaseReactiveRestClient.java b/client/synapse-client-rest/src/main/java/io/americanexpress/synapse/client/rest/client/BaseReactiveRestClient.java index 7c3d0e455..e00328ee9 100644 --- a/client/synapse-client-rest/src/main/java/io/americanexpress/synapse/client/rest/client/BaseReactiveRestClient.java +++ b/client/synapse-client-rest/src/main/java/io/americanexpress/synapse/client/rest/client/BaseReactiveRestClient.java @@ -13,9 +13,12 @@ */ package io.americanexpress.synapse.client.rest.client; +import java.time.Duration; import java.util.List; import io.americanexpress.synapse.client.rest.factory.BaseClientHttpHeadersFactory; +import io.americanexpress.synapse.framework.exception.ApplicationClientException; +import io.americanexpress.synapse.framework.exception.model.ErrorCode; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; @@ -29,6 +32,7 @@ import io.americanexpress.synapse.client.rest.model.QueryParameter; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import reactor.util.retry.Retry; /** * {@code BaseReactiveRestClient} class specifies the prototypes for all reactive REST clients. @@ -113,6 +117,37 @@ public Mono callMonoService(HttpHeaders headers, I clientRequest, List callMonoServiceWithRetry(HttpHeaders headers, I clientRequest, int numberOfRetries, long delayInMilliSeconds, List queryParameters, String... pathVariables) { + // Get the updated URL which may change in each client request due to path variables and/or query parameters + String updatedUrl = UrlBuilder.build(url, queryParameters, pathVariables); + + return webClient.method(httpMethod) + .uri(updatedUrl) + .headers(httpHeaders -> + httpHeaders.addAll(httpHeadersFactory.create(headers, clientRequest, updatedUrl))) + .body(Mono.just(clientRequest), clientRequestType) + .retrieve() + .onStatus(HttpStatus::isError, reactiveRestResponseErrorHandler) + .bodyToMono(clientResponseType) + .retryWhen(Retry.fixedDelay(numberOfRetries, Duration.ofMillis(delayInMilliSeconds)) + .filter(throwable -> throwable instanceof ApplicationClientException applicationClientException && applicationClientException.getErrorCode() == ErrorCode.GENERIC_5XX_ERROR) + .onRetryExhaustedThrow((retryBackoffSpec, retrySignal) -> { + throw new ApplicationClientException("External Service failed to process after max retries", ErrorCode.GENERIC_5XX_ERROR); + })); + } + /** * Get the mono response entity from the service given the HTTP headers and request body. * From fbdb391e9525245a441b7dd414245d5ef4d7f276 Mon Sep 17 00:00:00 2001 From: Wendy Hu Date: Wed, 23 Aug 2023 10:01:32 -0400 Subject: [PATCH 2/2] fix(): fixing failing build --- data/data-samples/sample-data-oracle-reactive-cp-book/pom.xml | 2 +- .../sample-service-reactive-oracle-cp-book/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/data-samples/sample-data-oracle-reactive-cp-book/pom.xml b/data/data-samples/sample-data-oracle-reactive-cp-book/pom.xml index 2e5db5f7a..25c9caa5c 100644 --- a/data/data-samples/sample-data-oracle-reactive-cp-book/pom.xml +++ b/data/data-samples/sample-data-oracle-reactive-cp-book/pom.xml @@ -18,7 +18,7 @@ data-samples io.americanexpress.synapse - 0.3.21-SNAPSHOT + 0.3.23-SNAPSHOT 4.0.0 diff --git a/service/service-samples/sample-service-reactive-oracle-cp-book/pom.xml b/service/service-samples/sample-service-reactive-oracle-cp-book/pom.xml index fb990b3c6..ce0df8581 100644 --- a/service/service-samples/sample-service-reactive-oracle-cp-book/pom.xml +++ b/service/service-samples/sample-service-reactive-oracle-cp-book/pom.xml @@ -18,7 +18,7 @@ io.americanexpress.synapse service-samples - 0.3.21-SNAPSHOT + 0.3.23-SNAPSHOT 4.0.0