Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping Resilience4j circuitbreaker around a service method with multiple arguments

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?

like image 281
P4L Avatar asked Sep 18 '25 00:09

P4L


1 Answers

You could use CircuitBreaker.decorateCallable:

CircuitBreaker.decorateCallable(circuitBreaker, () -> service.process(i, s))
like image 102
Alexander Pankin Avatar answered Sep 21 '25 04:09

Alexander Pankin