Search code examples
javaspring-bootresilience4j

Using Resilience4j TimeLimiter on service methods


Previously my project had Hystrix for timeouts. Since after Spring Boot upgrade it turned out that Hystrix is no longer supported/developed I needed alternative. One alternative seems to be Resilience4j but I get io.github.resilience4j.timelimiter.configure.IllegalReturnTypeException with it.

Example from Hystrix:

  @HystrixCommand(commandProperties = {@HystrixProperty(name = TIMEOUT, value = "60000")})
  public List<CustomBlahClass> getBlaBlaBla(...) {

If I now replace @HystrixCommand(...) with @TimeLimiter(name = "myTimeLimiter")

I get error:

io.github.resilience4j.timelimiter.configure.IllegalReturnTypeException: package.CustomBlahClass package.MyService#getBlaBlaBla has unsupported by @TimeLimiter return type. CompletionStage expected.

When I searched this issue I found that methods need to be of type CompletableFuture<T>.

Is refactoring all methods in all services to return CompletableFuture really the only option or am I missing something?


Solution

  • Yeah so this is poorly documented but it looks like Resiliance4j TimeLimiters only support Futures or CompletionStages.

    Alternatives appear to be using webflux and setting the async timeout property.