此版本仍在开发中,目前尚不被视为稳定版本。如需最新稳定版本,请使用 Spring-Cloud-CircuitBreaker 5.0.1spring-doc.cadn.net.cn

特定的舱壁配置

类似于证明默认的 'Bulkhead' 或 'ThreadPoolBulkhead' 配置,您可以通过创建一个 Customizer Bean 来实现,该 Bean 接收一个 Resilience4jBulkheadProviderspring-doc.cadn.net.cn

@Bean
public Customizer<Resilience4jBulkheadProvider> slowBulkheadProviderCustomizer() {
    return provider -> provider.configure(builder -> builder
        .bulkheadConfig(BulkheadConfig.custom().maxConcurrentCalls(1).build())
        .threadPoolBulkheadConfig(ThreadPoolBulkheadConfig.ofDefaults()), "slowBulkhead");
}

除了配置所创建的隔离舱(Bulkhead)之外,您还可以在隔离舱和线程池隔离舱被创建之后、返回给调用者之前对其进行自定义。为此,您可以使用 addBulkheadCustomizeraddThreadPoolBulkheadCustomizer 方法。spring-doc.cadn.net.cn

舱壁示例

@Bean
public Customizer<Resilience4jBulkheadProvider> customizer() {
    return provider -> provider.addBulkheadCustomizer(bulkhead -> bulkhead.getEventPublisher()
        .onCallRejected(slowRejectedConsumer)
        .onCallFinished(slowFinishedConsumer), "slowBulkhead");
}

线程池舱壁示例

@Bean
public Customizer<Resilience4jBulkheadProvider> slowThreadPoolBulkheadCustomizer() {
    return provider -> provider.addThreadPoolBulkheadCustomizer(threadPoolBulkhead -> threadPoolBulkhead.getEventPublisher()
        .onCallRejected(slowThreadPoolRejectedConsumer)
        .onCallFinished(slowThreadPoolFinishedConsumer), "slowThreadPoolBulkhead");
}