spring-cloud / spring-cloud-circuitbreaker

Spring Cloud Circuit Breaker API and Implementations
Apache License 2.0
329 stars 110 forks source link

How to use semaphore bulkhead by default in spring-cloud-resilience4j? #113

Closed carrypann closed 2 years ago

carrypann commented 3 years ago

There is a piece of code in Resilience4jBulkheadProvider.java(119-129)

if (bulkheadRegistry.find(id).isPresent() && !threadPoolBulkheadRegistry.find(id).isPresent()) {
    Bulkhead bulkhead = bulkheadRegistry.bulkhead(id, configuration.getBulkheadConfig());
    CompletableFuture<T> asyncCall = CompletableFuture.supplyAsync(supplier);
    return Bulkhead.decorateCompletionStage(bulkhead, () -> asyncCall);
}
else {
    ThreadPoolBulkhead threadPoolBulkhead = threadPoolBulkheadRegistry.bulkhead(id,
            configuration.getThreadPoolBulkheadConfig());
    return threadPoolBulkhead.decorateSupplier(supplier);
}

It caused that resilience4j will use bulkhead of semaphore mode defaultly if id not in bulkheadRegistry.

I use spring-cloud-resilience4j and spring-cloud-openfeign, and I want to use a default bulkhead config which in semaphore mode by puttingresilience4j.bulkhead.configs.default in application.yaml, but it does not work. How can i solve the problem?

carrypann commented 3 years ago

The most recent version 2020.0.3-SNAPSHOT of the document said that Spring Cloud CircuitBreaker Resilience4j uses FixedThreadPoolBulkhead by default, however, the SemaphoreBulkhead should work well across a variety of threading and I/O models. So can you consider changing to use SemaphoreBulkhead by default? Or providing a method to set default mode by users?

robertmcnees commented 2 years ago

Closing as duplicate to #119