Class DmxCircuitBreaker

java.lang.Object
dmx.fun.resilience4j.DmxCircuitBreaker

@NullMarked public final class DmxCircuitBreaker extends Object
dmx-fun adapter for Resilience4J CircuitBreaker.

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

DmxCircuitBreaker cb = DmxCircuitBreaker.of("orders", CircuitBreakerConfig.ofDefaults());

Try<Response>                               r1 = cb.executeTry(() -> orderService.place(cmd));
Result<Response, Throwable>                 r2 = cb.executeResult(() -> orderService.place(cmd));
Result<Response, CallNotPermittedException> r3 = cb.executeResultTyped(() -> orderService.place(cmd));
  • Method Details

    • of

      public static DmxCircuitBreaker of(io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker)
      Wraps an existing CircuitBreaker instance.
      Parameters:
      circuitBreaker - the Resilience4J circuit breaker to wrap
      Returns:
      a new DmxCircuitBreaker backed by the given circuit breaker
    • of

      public static DmxCircuitBreaker of(String name, io.github.resilience4j.circuitbreaker.CircuitBreakerConfig config)
      Creates a new CircuitBreaker from the given name and config, then wraps it.
      Parameters:
      name - the circuit breaker name
      config - the circuit breaker configuration
      Returns:
      a new DmxCircuitBreaker backed by the created circuit breaker
    • executeTry

      public <V> Try<V> executeTry(CheckedSupplier<V> supplier)
      Executes the supplier through the circuit breaker.
      Type Parameters:
      V - the value type
      Parameters:
      supplier - the operation to execute
      Returns:
      Success(value) on success, Failure(CallNotPermittedException) when the circuit is open, or Failure(cause) when the call itself fails
    • executeResult

      public <V> Result<V, Throwable> executeResult(CheckedSupplier<V> supplier)
      Executes the supplier through the circuit breaker.
      Type Parameters:
      V - the value type
      Parameters:
      supplier - the operation to execute
      Returns:
      Ok(value) on success, Err(CallNotPermittedException) when the circuit is open, or Err(cause) when the call itself fails
    • executeResultTyped

      public <V> Result<V, io.github.resilience4j.circuitbreaker.CallNotPermittedException> executeResultTyped(CheckedSupplier<V> supplier)
      Executes the supplier through the circuit breaker, surfacing circuit-open rejections as a typed error.
      Type Parameters:
      V - the value type
      Parameters:
      supplier - the operation to execute
      Returns:
      Ok(value) on success, Err(CallNotPermittedException) when the circuit is open; other exceptions from the call propagate as unchecked