I want to decorate my service call with the newest resilience4j circuit breaker, my current code looks like:
@Bean
public Function<MyObject1, MyObject2> decoratedFunction(MyService myService) {
CircuitBreakerRegistry registry = CircuitBreakerRegistry.ofDefaults();
CircuitBreaker circuitBreaker = registry.circuitBreaker("circuitBreaker");
//decorateFunction method no longer exists :/
return circuitBreaker.decorateFunction((myObject1) -> myService.makeACall(myObject1))
}
There used to be a method called decorateFunction which I would love to use but for an unknown reason it was removed in the latest version of resilience4j (I'm using latest 1.4 version)
Anyone knows why this function was removed and what is the current replacement for it?
I see there are methods like decorateSupplier but I need to pass a parameter to my service (which is not allowed in case of supplier)
Please use our Spring Boot Starter instead of creating your own CircuitBreakerRegistry. Then inject the auto-created CircuitBreakerRegistry into your code and retrieve a CircuitBreaker instance.
CircuitBreaker circuitBreaker = registry.circuitBreaker("circuitBreaker");
In your service code do:
public MyObject2 makeACall(MyObject1 myObject1) {
return circuitBreaker.executeSupplier(() -> myService.makeACall(myObject1))
}
Looks like in the latest version of resilience this method is static for some reason, so to use it simply:
@Bean
public Function<MyObject1, MyObject2> decoratedFunction(MyService myService) {
CircuitBreakerRegistry registry = CircuitBreakerRegistry.ofDefaults();
CircuitBreaker circuitBreaker = registry.circuitBreaker("circuitBreaker");
//decorateFunction method is static now
return CircuitBreaker.decorateFunction(circuitBreaker, (myObject1) -> myService.makeACall(myObject1))
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With