Resilience4j fallbackMethod issue

18 views Asked by At

I am using following dependency :

implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j'

In my following code :

    @Override
@Retry(name = "ingestStockEvent", fallbackMethod = "ingestUnprocessedStockEvent")
public void ingestStockEvent(StoreStockMovementEvent storeStockMovementEvent) {
    try {
        CreateStoreStockMovementRequest createStoreStockMovementRequest = mapEventToCreateRequest(storeStockMovementEvent);
        stockServiceClient.ingestStockEvent(createStoreStockMovementRequest);
    } catch (WebClientResponseException webClientResponseException) {
        if (webClientResponseException.getStatusCode() == HttpStatus.CONFLICT) {
            throw new DuplicateEventException(
                String.format(
                    "Skipping persistence for storeStockMovement with eventId {%s} and stockTransactionId {%s} as it already exists",
                    storeStockMovementEvent.eventHeader().id(), storeStockMovementEvent.stockTransaction().stockTransactionId()));
        } else {
            throw webClientResponseException;
        }
    }

}

public void ingestUnprocessedStockEvent(StoreStockMovementEvent storeStockMovementEvent, RuntimeException runtimeException) {
    log.error("ingestion failed {}", storeStockMovementEvent);
    throw new IngestionFailedException(String.format("Failed to ingest event with eventId {%s} and traceId {%s}. Trace:: {%s}",
        storeStockMovementEvent.eventHeader().id(), storeStockMovementEvent.eventHeader().traceId(), runtimeException));
}

And following properties :

resilience4j:
  retry:
    instances:
      ingestStockEvent:
        maxAttempts: 3
        waitDuration: 10s
        enableExponentialBackoff: true
        exponentialBackoffMultiplier: 1.25
        ignoreExceptions:
          - com.myOrg.commons.exception.DuplicateEventException

What I was looking for is when I throw the DuplicateEventException I don't want retry to happen, and at the same time the fallbackMethod not to be executed.

But as per this discussion even in ignoredException case fallback method gets executed.

So, is there any solution for the requirement which I have, where I don't want the ignored exception to execute the fallback method which gets executed in all retried exception case.

0

There are 0 answers