resilience4j

Resilience4j is a fault tolerance library for Java™

Resilience4j is a lightweight fault tolerance library inspired by Netflix Hystrix, but designed for functional programming.
Resilience4j provides higher-order functions (decorators) to enhance any functional interface, lambda expression or method reference with a Circuit Breaker, Rate Limiter, Retry or Bulkhead. You can stack more than one decorator on any functional interface, lambda expression or method reference. The advantage is that you have the choice to select the decorators you need and nothing else.

Supplier<String> supplier = () -> service.sayHelloWorld(param1);

String result = Decorators.ofSupplier(supplier)
  .withBulkhead(Bulkhead.ofDefaults("name"))
  .withCircuitBreaker(CircuitBreaker.ofDefaults("name"))
  .withRetry(Retry.ofDefaults("name"))
  .withFallback(asList(CallNotPermittedException.class, BulkheadFullException.class),  
      throwable -> "Hello from fallback")
  .get()

With Resilience4j you don’t have to go all-in, you can pick what you need.

Get Started

Examples

Examples of resilience4j-bulkhead

Create a BulkheadRegistry

Create a BulkheadRegistry with a custom BulkheadConfig.

// Create a custom configuration for a Bulkhead
BulkheadConfig config = BulkheadConfig.custom()
        .maxConcurrentCalls(10)
        .maxWaitDuration(Duration.ofMillis(1))
        .build();

// Create a BulkheadRegistry with a custom global configuration
BulkheadRegistry bulkheadRegistry =
        BulkheadRegistry.of(config);

Create a Bulkhead

Get a Bulkhead from the BulkheadRegistry with the global default configuration

Bulkhead bulkhead = bulkheadRegistry
  .bulkhead("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();

Examples


Examples of resilience4j-bulkhead

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.