Adding back bulkhead document
This commit is contained in:
@@ -94,6 +94,105 @@ public Customizer<ReactiveResilience4JCircuitBreakerFactory> slowCusomtizer() {
|
||||
----
|
||||
====
|
||||
|
||||
==== Bulkhead pattern supporting
|
||||
If `resilience4j-bulkhead` is on the classpath, Spring Cloud CircuitBreaker will wrap all methods with a Resilience4j Bulkhead.
|
||||
You can disable the Resilience4j Bulkhead by setting `spring.cloud.circuitbreaker.bulkhead.resilience4j.enabled` to `false`.
|
||||
|
||||
Spring Cloud CircuitBreaker Resilience4j provides two implementation of bulkhead pattern:
|
||||
|
||||
* a `SemaphoreBulkhead` which uses Semaphores
|
||||
* a `FixedThreadPoolBulkhead` which uses a bounded queue and a fixed thread pool.
|
||||
|
||||
By default, Spring Cloud CircuitBreaker Resilience4j uses `FixedThreadPoolBulkhead`. For more information on implementation
|
||||
of Bulkhead patterns see the https://resilience4j.readme.io/docs/bulkhead[Resilience4j Bulkhead].
|
||||
|
||||
The `Customizer<Resilience4jBulkheadProvider>` can be used to provide a default `Bulkhead` and `ThreadPoolBulkhead` configuration.
|
||||
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
@Bean
|
||||
public Customizer<Resilience4jBulkheadProvider> defaultBulkheadCustomizer() {
|
||||
return provider -> provider.configureDefault(id -> new Resilience4jBulkheadConfigurationBuilder()
|
||||
.bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(4).build())
|
||||
.threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.custom().coreThreadPoolSize(1).maxThreadPoolSize(1).build())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
==== Specific Bulkhead Configuration
|
||||
|
||||
Similarly to proving a default 'Bulkhead' or 'ThreadPoolBulkhead' configuration, you can create a `Customize` bean this
|
||||
is passed a `Resilience4jBulkheadProvider`.
|
||||
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
@Bean
|
||||
public Customizer<Resilience4jBulkheadProvider> slowBulkheadProviderCustomizer() {
|
||||
return provider -> provider.configure(builder -> builder
|
||||
.bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(1).build())
|
||||
.threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.ofDefaults()), "slowBulkhead");
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
In addition to configuring the Bulkhead that is created you can also customize the bulkhead and thread pool bulkhead after they
|
||||
have been created but before they are returned to caller. To do this you can use the `addBulkheadCustomizer` and `addThreadPoolBulkheadCustomizer`
|
||||
methods.
|
||||
|
||||
===== Bulkhead Example
|
||||
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
@Bean
|
||||
public Customizer<Resilience4jBulkheadProvider> customizer() {
|
||||
return provider -> provider.addBulkheadCustomizer(bulkhead -> bulkhead.getEventPublisher()
|
||||
.onCallRejected(slowRejectedConsumer)
|
||||
.onCallFinished(slowFinishedConsumer), "slowBulkhead");
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
===== Thread Pool Bulkhead Example
|
||||
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
@Bean
|
||||
public Customizer<Resilience4jBulkheadProvider> slowThreadPoolBulkheadCustomizer() {
|
||||
return provider -> provider.addThreadPoolBulkheadCustomizer(threadPoolBulkhead -> threadPoolBulkhead.getEventPublisher()
|
||||
.onCallRejected(slowThreadPoolRejectedConsumer)
|
||||
.onCallFinished(slowThreadPoolFinishedConsumer), "slowThreadPoolBulkhead");
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
==== Bulkhead Properties Configuration
|
||||
|
||||
You can configure ThreadPoolBulkhead and SemaphoreBulkhead instances in your application's configuration properties file.
|
||||
Property configuration has higher priority than Java `Customizer` configuration.
|
||||
|
||||
====
|
||||
[source]
|
||||
----
|
||||
resilience4j.thread-pool-bulkhead:
|
||||
instances:
|
||||
backendA:
|
||||
maxThreadPoolSize: 1
|
||||
coreThreadPoolSize: 1
|
||||
resilience4j.bulkhead:
|
||||
instances:
|
||||
backendB:
|
||||
maxConcurrentCalls: 10
|
||||
----
|
||||
====
|
||||
|
||||
For more inforamtion on the Resilience4j property configuration, see https://resilience4j.readme.io/docs/getting-started-3#configuration[Resilience4J Spring Boot 2 Configuration].
|
||||
|
||||
==== Collecting Metrics
|
||||
|
||||
Spring Cloud Circuit Breaker Resilience4j includes auto-configuration to setup metrics collection as long as the right
|
||||
|
||||
Reference in New Issue
Block a user