特定舱壁配置

与提供默认“Bulkhead”或“ThreadPoolBulkhead”配置类似,您可以创建一个 Customizer bean,该 bean 会传递一个 Resilience4jBulkheadProvider

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

除了配置要创建的舱壁外,您还可以在舱壁和线程池舱壁创建后但在返回给调用者之前对其进行自定义。为此,您可以使用 addBulkheadCustomizeraddThreadPoolBulkheadCustomizer 方法。

舱壁示例

@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");
}
© . This site is unofficial and not affiliated with VMware.