From f174047c2c0108fa4b8df86c5f1e628ebe29f4d0 Mon Sep 17 00:00:00 2001 From: Giulia Tremolada <124147597+giulia-tremolada@users.noreply.github.com> Date: Mon, 27 May 2024 14:10:47 +0200 Subject: [PATCH] [SELC-4883] feat: add retry on retrieveGeographicTaxonomies (#500) --- app/src/main/resources/config/application.yml | 9 +++++++++ connector/rest/pom.xml | 4 ++++ .../connector/rest/PartyRegistryProxyConnectorImpl.java | 9 ++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/main/resources/config/application.yml b/app/src/main/resources/config/application.yml index e2d0644f6..ebc4a0129 100644 --- a/app/src/main/resources/config/application.yml +++ b/app/src/main/resources/config/application.yml @@ -49,3 +49,12 @@ core: type: ${CORE_USER_EVENT_SERVICE_TYPE:ignore} contract-event-service: type: ${CORE_CONTRACT_EVENT_SERVICE_TYPE:ignore} + resilience4j: + retry: + retry-aspect-order: 1 + instances: + retryTimeout: + max-attempts: 3 + wait-duration: 5s + retry-exceptions: + - feign.RetryableException \ No newline at end of file diff --git a/connector/rest/pom.xml b/connector/rest/pom.xml index 985c728a5..dd13b2760 100644 --- a/connector/rest/pom.xml +++ b/connector/rest/pom.xml @@ -30,6 +30,10 @@ io.github.openfeign feign-okhttp + + io.github.resilience4j + resilience4j-spring-boot2 + diff --git a/connector/rest/src/main/java/it/pagopa/selfcare/mscore/connector/rest/PartyRegistryProxyConnectorImpl.java b/connector/rest/src/main/java/it/pagopa/selfcare/mscore/connector/rest/PartyRegistryProxyConnectorImpl.java index a0eb2abba..0053c3ca5 100644 --- a/connector/rest/src/main/java/it/pagopa/selfcare/mscore/connector/rest/PartyRegistryProxyConnectorImpl.java +++ b/connector/rest/src/main/java/it/pagopa/selfcare/mscore/connector/rest/PartyRegistryProxyConnectorImpl.java @@ -1,6 +1,7 @@ package it.pagopa.selfcare.mscore.connector.rest; import feign.FeignException; +import io.github.resilience4j.retry.annotation.Retry; import it.pagopa.selfcare.commons.base.logging.LogUtils; import it.pagopa.selfcare.mscore.api.PartyRegistryProxyConnector; import it.pagopa.selfcare.mscore.connector.rest.client.PartyRegistryProxyRestClient; @@ -30,6 +31,7 @@ @Service public class PartyRegistryProxyConnectorImpl implements PartyRegistryProxyConnector { + public static final String CODE_IS_REQUIRED = "Code is required"; private final PartyRegistryProxyRestClient restClient; private final AooMapper aooMapper; private final UoMapper uoMapper; @@ -137,9 +139,10 @@ private CategoryProxyInfo convertCategoryProxyInfo(ProxyCategoryResponse respons } @Override + @Retry(name = "retryTimeout") public GeographicTaxonomies getExtByCode(String code) { log.debug(LogUtils.CONFIDENTIAL_MARKER, "getExtByCode code = {}", code); - Assert.hasText(code, "Code is required"); + Assert.hasText(code, CODE_IS_REQUIRED); GeographicTaxonomiesResponse result = restClient.getExtByCode(code); log.debug(LogUtils.CONFIDENTIAL_MARKER, "getExtByCode result = {}", result); return toGeoTaxonomies(result); @@ -148,7 +151,7 @@ public GeographicTaxonomies getExtByCode(String code) { @Override public AreaOrganizzativaOmogenea getAooById(String aooId) { log.debug("getAooById id = {}", aooId); - Assert.hasText(aooId, "Code is required"); + Assert.hasText(aooId, CODE_IS_REQUIRED); AooResponse result = restClient.getAooById(aooId); log.debug("getAooById id = {}", aooId); return aooMapper.toEntity(result); @@ -157,7 +160,7 @@ public AreaOrganizzativaOmogenea getAooById(String aooId) { @Override public UnitaOrganizzativa getUoById(String uoId) { log.debug("getUoById id = {}", uoId); - Assert.hasText(uoId, "Code is required"); + Assert.hasText(uoId, CODE_IS_REQUIRED); UoResponse result = restClient.getUoById(uoId); log.debug("getUoById id = {}", uoId); return uoMapper.toEntity(result);