Class DmxCircuitBreaker
java.lang.Object
dmx.fun.resilience4j.DmxCircuitBreaker
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 Summary
Modifier and TypeMethodDescriptionexecuteResult(CheckedSupplier<V> supplier) Executes the supplier through the circuit breaker.<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.<V> Try<V> executeTry(CheckedSupplier<V> supplier) Executes the supplier through the circuit breaker.static DmxCircuitBreakerof(io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker) Wraps an existingCircuitBreakerinstance.static DmxCircuitBreakerCreates a newCircuitBreakerfrom the given name and config, then wraps it.
-
Method Details
-
of
public static DmxCircuitBreaker of(io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker) Wraps an existingCircuitBreakerinstance.- Parameters:
circuitBreaker- the Resilience4J circuit breaker to wrap- Returns:
- a new
DmxCircuitBreakerbacked by the given circuit breaker
-
of
public static DmxCircuitBreaker of(String name, io.github.resilience4j.circuitbreaker.CircuitBreakerConfig config) Creates a newCircuitBreakerfrom the given name and config, then wraps it.- Parameters:
name- the circuit breaker nameconfig- the circuit breaker configuration- Returns:
- a new
DmxCircuitBreakerbacked by the created circuit breaker
-
executeTry
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, orFailure(cause)when the call itself fails
-
executeResult
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, orErr(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
-