Class DmxRateLimiter
java.lang.Object
dmx.fun.resilience4j.DmxRateLimiter
dmx-fun adapter for Resilience4J
RateLimiter.
Executes a supplier through the rate limiter and returns a dmx-fun type instead of throwing. Configure the rate limiter using the native Resilience4J API:
DmxRateLimiter rl = DmxRateLimiter.of("payments", RateLimiterConfig.ofDefaults());
Try<Receipt> r1 = rl.executeTry(() -> gateway.charge(amount));
Result<Receipt, Throwable> r2 = rl.executeResult(() -> gateway.charge(amount));
Result<Receipt, RequestNotPermitted> r3 = rl.executeResultTyped(() -> gateway.charge(amount));
-
Method Summary
Modifier and TypeMethodDescriptionexecuteResult(CheckedSupplier<V> supplier) Executes the supplier through the rate limiter.<V> Result<V, io.github.resilience4j.ratelimiter.RequestNotPermitted> executeResultTyped(CheckedSupplier<V> supplier) Executes the supplier through the rate limiter, surfacing rate-limit rejections as a typed error.<V> Try<V> executeTry(CheckedSupplier<V> supplier) Executes the supplier through the rate limiter.static DmxRateLimiterof(io.github.resilience4j.ratelimiter.RateLimiter rateLimiter) Wraps an existingRateLimiterinstance.static DmxRateLimiterCreates a newRateLimiterfrom the given name and config, then wraps it.
-
Method Details
-
of
Wraps an existingRateLimiterinstance.- Parameters:
rateLimiter- the Resilience4J rate limiter to wrap- Returns:
- a new
DmxRateLimiterbacked by the given rate limiter
-
of
public static DmxRateLimiter of(String name, io.github.resilience4j.ratelimiter.RateLimiterConfig config) Creates a newRateLimiterfrom the given name and config, then wraps it.- Parameters:
name- the rate limiter nameconfig- the rate limiter configuration- Returns:
- a new
DmxRateLimiterbacked by the created rate limiter
-
executeTry
Executes the supplier through the rate limiter.- Type Parameters:
V- the value type- Parameters:
supplier- the operation to execute- Returns:
Success(value)on success,Failure(RequestNotPermitted)when the rate limit is exceeded, orFailure(cause)when the call itself fails
-
executeResult
Executes the supplier through the rate limiter.- Type Parameters:
V- the value type- Parameters:
supplier- the operation to execute- Returns:
Ok(value)on success,Err(cause)on any failure
-
executeResultTyped
public <V> Result<V, io.github.resilience4j.ratelimiter.RequestNotPermitted> executeResultTyped(CheckedSupplier<V> supplier) Executes the supplier through the rate limiter, surfacing rate-limit rejections as a typed error.- Type Parameters:
V- the value type- Parameters:
supplier- the operation to execute- Returns:
Ok(value)on success,Err(RequestNotPermitted)when the rate limit is exceeded; other exceptions from the call propagate as unchecked
-