Class DmxRetry

java.lang.Object
dmx.fun.resilience4j.DmxRetry

@NullMarked public final class DmxRetry extends Object
dmx-fun adapter for Resilience4J Retry.

Executes a supplier through the configured retry policy and returns a dmx-fun type instead of throwing. Configure the retry using the native Resilience4J API:

RetryConfig config = RetryConfig.custom()
    .maxAttempts(3)
    .waitDuration(Duration.ofMillis(200))
    .retryOnException(IOException.class::isInstance)
    .build();

DmxRetry retry = DmxRetry.of("my-retry", config);

Try<Response>               r1 = retry.executeTry(() -> httpClient.get(url));
Result<Response, Throwable> r2 = retry.executeResult(() -> httpClient.get(url));
  • Method Details

    • of

      public static DmxRetry of(io.github.resilience4j.retry.Retry retry)
      Wraps an existing Retry instance.
      Parameters:
      retry - the Resilience4J retry policy to wrap
      Returns:
      a new DmxRetry backed by the given retry policy
    • of

      public static DmxRetry of(String name, io.github.resilience4j.retry.RetryConfig config)
      Creates a new Retry from the given name and config, then wraps it.
      Parameters:
      name - the retry policy name
      config - the retry configuration
      Returns:
      a new DmxRetry backed by the created retry policy
    • executeTry

      public <V> Try<V> executeTry(CheckedSupplier<V> supplier)
      Executes the supplier through the retry policy.
      Type Parameters:
      V - the value type
      Parameters:
      supplier - the operation to execute
      Returns:
      Success(value) if the call eventually succeeds, Failure(cause) if all attempts are exhausted
    • executeResult

      public <V> Result<V, Throwable> executeResult(CheckedSupplier<V> supplier)
      Executes the supplier through the retry policy.
      Type Parameters:
      V - the value type
      Parameters:
      supplier - the operation to execute
      Returns:
      Ok(value) if the call eventually succeeds, Err(cause) if all attempts are exhausted