Support `@CircuitBreaker` on suspend functions (including `suspend fun` fallback methods) in Spring Boot 2
See original GitHub issueResilience4j version: 1.7.1 Java version: 16 kotlin version: 1.5.30
@CircuitBreaker
does not work with bean suspend functions even when it boasts Kotlin Coroutines support.
First, FallbackMethod.create(...)
will always fail to find the fallback method because of how kotlin inserts a kotlin.coroutines.Continuation<T>
as the last parameter of suspend functions. This is illustrated below.
@Service class MyBean {
@CircuitBreaker("breakerName", fallbackMethod = "aFallbackMethod")
suspend fun aMethod(aParam: String): String { ... }
suspend fun aFallbackMethod(theParam: String, error: Throwable): String { ... }
}
For the above bean the runtime method signatures are
aMethod(String, Continuation): Object
&
aFallbackMethod(String, Throwable, Continuation): Object
which is why the fallback method cannot be determined, because the throwable is not the last parameter in the fallback function.
Also, being a suspend function, its inherently asynchronous and needs to be explicitly handled (or wrapped somehow) inside of CircuitBreakerAspect
to function correctly
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
@RobWin Sounds good. I will open a PR soon for this.
No