3

Resilience4j-circuitbreaker allows us to wrap a service using decorator functions, but from what I can tell it only allows functional interfaces such as Supplier, Consumer, and Function which accept at most 1 input.

If I have a service which has a method which accepts 2 arguments, how would i be able to wrap it with the circuitbreaker?

In https://www.baeldung.com/resilience4j:

interface RemoteService {
    int process(int i);
}

CircuitBreakerRegistry registry = CircuitBreakerRegistry.of(config);
CircuitBreaker circuitBreaker = registry.circuitBreaker("my");
Function<Integer, Integer> decorated = CircuitBreaker
  .decorateFunction(circuitBreaker, service::process);

If process(int i) was something like process(int i, String s), which decorator Function would be able to be used for this purpose?

P4L
  • 98
  • 3
  • 9

1 Answers1

3

You could use CircuitBreaker.decorateCallable:

CircuitBreaker.decorateCallable(circuitBreaker, () -> service.process(i, s))
Alexander Pankin
  • 3,787
  • 1
  • 13
  • 23