swathi manda
swathi manda

Reputation: 131

Use both functional Programming and Spring annotations - Resilience4j

I am using resilience4j Library for fault tolerance with Spring Boot. I want to maintain resilience4j configuration in application.yml file.

I want to use resilience 4j annotations as it helps to keep the business logic clean.

But in cases where the annotations do not work(like AOP does not allow calling methods of the same class and not being able to annotate Spring data repository methods) I want to use the functional programming approach .

For the configuration given in application.yml file , how do I create CircuitBreaker and Retry beans in my Spring boot applications so that I can decorate calls with high order functional programming in some scenarios and use annotations in other.

My current configuration:

resilience4j:
  retry:
    configs:
      default:
        max-retry-attempts: 3
        wait-duration: 5s
        retry-exception-predicate: com.example.resilience.predicate.RetryExceptionPredicate
        retry-exceptions:
          - java.io.IOException
          - java.util.concurrent.TimeoutException
    instances:
      ierp-test:
        base-config: default

Upvotes: 1

Views: 624

Answers (2)

gstackoverflow
gstackoverflow

Reputation: 37034

Such configuration will wrap circuitbreaker over retry

resilience4j:
  retry:
    retry-aspect-order: 2
    instances:
      myRertry:
    ...
circuitbreaker:
    circuit-breaker-aspect-order: 1
    instances:
      myCircuitBreaker:
    ...

Upvotes: 0

Robert Winkler
Robert Winkler

Reputation: 1907

Just inject the CircuitBreakerRegistry into you bean.

Upvotes: 0

Related Questions