question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best implementation for circuitBreaker + ThreadPoolBulkhead + timeLimiter + retry

See original GitHub issue

Hi! I’m migrating a task from hystrix to resilience4j where I need the circuitBreaker, ThreadPoolBulkhead and timeLimiter with a fallback. I was able to have a good implementation for circuitBreaker and timelimiter, but now, that I’m adding the needed ThreadPoolBulkhead, I’m not sure if the implementation is the best:

    protected Future<ErrorCodes> execute() throws ExecutionException, InterruptedException {
        CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker("sample", "circuitBreakerConfig");
        ThreadPoolBulkhead bulkhead = bulkheadRegistry.bulkhead("sample", "threadPoolBulkheadConfigForTransactions");

        Supplier<CompletionStage<ErrorCodes>> completionStageSupplier = () -> CompletableFuture.supplyAsync(this::run);
        Supplier<CompletionStage<ErrorCodes>> decoratedCompletionStage = Decorators.ofCompletionStage(completionStageSupplier)
                .withCircuitBreaker(circuitBreaker)
                .decorate();

        CompletableFuture<ErrorCodes> bulkheadExecutor = bulkhead.executeSupplier(decoratedCompletionStage).toCompletableFuture().get().toCompletableFuture();
        Callable<ErrorCodes> result = TimeLimiter.decorateFutureSupplier(TimeLimiter.of(timeLimiterConfig), () -> bulkheadExecutor);

        return Future.of(result::call).recover(this::getFallback);
    }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:23 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
IsabelPalomarcommented, Jan 31, 2020

Can I close the issue?

Sure! Thanks!

1reaction
RobWincommented, Jan 31, 2020

Even better:

CompletableFuture<String> future = Decorators
    .ofSupplier(() -> helloWorldService.returnHelloWorld())
    .withThreadPoolBulkhead(ThreadPoolBulkhead.ofDefaults("helloBackend"))
    .withTimeLimiter(TimeLimiter.ofDefaults(), Executors.newSingleThreadScheduledExecutor())
    .withCircuitBreaker(circuitBreaker)
    .withFallback(TimeoutException.class, (e) -> "Recovery")
    .get().toCompletableFuture();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Integrating circuitbreaker, retry and timelimiter in Resilience4j
You are using timeLimiter.executeFutureSupplier which executes the Future instead of decorating it. Please use it in exactly this order:
Read more >
Getting Started - resilience4j
You can configure your CircuitBreaker, Retry, RateLimiter, Bulkhead, Thread pool bulkhead and TimeLimiter instances in Spring Boot's
Read more >
A quick guide to Resilience4j with Spring Boot.
With Spring Boot, Resilience4j is preferred over Hystrix for implementing fault tolerance patterns like Circuit breaker, bulkhead, timeouts, rate limiters and ...
Read more >
Spring Cloud Circuit Breaker
The Spring Cloud CircuitBreaker project contains implementations for Resilience4J and Spring Retry. The APIs implemented in Spring Cloud CircuitBreaker live ...
Read more >
Guide to Resilience4j - Baeldung
1. Overview · 2. Maven Setup · 3. Circuit Breaker · 4. Rate Limiter · 5. Bulkhead · 6. Retry · 7. Cache...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found