特定隔板配置

与证明默认的 'Bulkhead' 或 'ThreadPoolBulkhead' 配置类似,你可以创建一个 bean 将传递一个 .CustomizerResilience4jBulkheadProviderspring-doc.cn

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

除了配置创建的 Bulkhead 之外,您还可以在 bulkhead 和线程池 bulkhead 之后对其进行自定义 已创建,但在它们返回给调用方之前。为此,您可以使用 and 方法。addBulkheadCustomizeraddThreadPoolBulkheadCustomizerspring-doc.cn

隔板示例

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

Thread Pool Bulkhead 示例

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