Examples
Examples of resilience4j-bulkhead
Create a BulkheadRegistry
Create a BulkheadRegistry with a custom BulkheadConfig.
// Create a custom configuration for a RateLimiter
RateLimiterConfig config = RateLimiterConfig.custom()
.limitRefreshPeriod(Duration.ofMillis(1))
.limitForPeriod(10)
.timeoutDuration(Duration.ofMillis(25))
.build();
// Create a RateLimiterRegistry with a custom global configuration
RateLimiterRegistry rateLimiterRegistry = RateLimiterRegistry.of(config);
Create a Bulkhead
Get a Bulkhead from the BulkheadRegistry with the global default configuration
Bulkhead bulkhead = bulkheadRegistry
.circuitBreaker("name");
Decorate a functional interface
Decorate your call to BackendService.doSomething()
with a Bulkhead and execute the decorated supplier and recover from any exception.
Supplier<String> decoratedSupplier = Bulkhead
.decorateSupplier(retry, backendService::doSomething);
String result = Try.ofSupplier(decoratedSupplier)
.recover(throwable -> "Hello from Recovery").get();
Updated over 5 years ago