Best implementation for circuitBreaker + ThreadPoolBulkhead + timeLimiter + retry
See original GitHub issueHi! 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:
- Created 4 years ago
- Comments:23 (12 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure! Thanks!
Even better: