Search in sources :

Example 1 with ThreadPoolBulkheadRegistry

use of io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry in project resilience4j by resilience4j.

the class ThreadPoolBulkheadFactory method threadPoolBulkheadRegistry.

@Singleton
@Requires(beans = ThreadPoolBulkheadConfigurationProperties.class)
public ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry(ThreadPoolBulkheadConfigurationProperties bulkheadConfigurationProperties, @ThreadPoolBulkheadQualifier EventConsumerRegistry<BulkheadEvent> bulkheadEventConsumerRegistry, @ThreadPoolBulkheadQualifier RegistryEventConsumer<ThreadPoolBulkhead> threadPoolBulkheadRegistryEventConsumer, @ThreadPoolBulkheadQualifier CompositeCustomizer<ThreadPoolBulkheadConfigCustomizer> compositeThreadPoolBulkheadCustomizer) {
    ThreadPoolBulkheadRegistry bulkheadRegistry = createBulkheadRegistry(bulkheadConfigurationProperties, threadPoolBulkheadRegistryEventConsumer, compositeThreadPoolBulkheadCustomizer);
    registerEventConsumer(bulkheadRegistry, bulkheadEventConsumerRegistry, bulkheadConfigurationProperties);
    bulkheadConfigurationProperties.getBackends().forEach((name, properties) -> bulkheadRegistry.bulkhead(name, bulkheadConfigurationProperties.createThreadPoolBulkheadConfig(name, compositeThreadPoolBulkheadCustomizer)));
    return bulkheadRegistry;
}
Also used : ThreadPoolBulkheadRegistry(io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry) Requires(io.micronaut.context.annotation.Requires) Singleton(javax.inject.Singleton)

Example 2 with ThreadPoolBulkheadRegistry

use of io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry in project resilience4j by resilience4j.

the class ThreadPoolBulkheadConfiguration method threadPoolBulkheadRegistry.

/**
 * @param bulkheadConfigurationProperties bulk head spring configuration properties
 * @param bulkheadEventConsumerRegistry   the bulk head event consumer registry
 * @return the ThreadPoolBulkheadRegistry with all needed setup in place
 */
@Bean
public ThreadPoolBulkheadRegistry threadPoolBulkheadRegistry(ThreadPoolBulkheadConfigurationProperties bulkheadConfigurationProperties, EventConsumerRegistry<BulkheadEvent> bulkheadEventConsumerRegistry, RegistryEventConsumer<ThreadPoolBulkhead> threadPoolBulkheadRegistryEventConsumer, @Qualifier("compositeThreadPoolBulkheadCustomizer") CompositeCustomizer<ThreadPoolBulkheadConfigCustomizer> compositeThreadPoolBulkheadCustomizer) {
    ThreadPoolBulkheadRegistry bulkheadRegistry = createBulkheadRegistry(bulkheadConfigurationProperties, threadPoolBulkheadRegistryEventConsumer, compositeThreadPoolBulkheadCustomizer);
    registerEventConsumer(bulkheadRegistry, bulkheadEventConsumerRegistry, bulkheadConfigurationProperties);
    bulkheadConfigurationProperties.getBackends().forEach((name, properties) -> bulkheadRegistry.bulkhead(name, bulkheadConfigurationProperties.createThreadPoolBulkheadConfig(name, compositeThreadPoolBulkheadCustomizer)));
    return bulkheadRegistry;
}
Also used : ThreadPoolBulkheadRegistry(io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry) Bean(org.springframework.context.annotation.Bean)

Example 3 with ThreadPoolBulkheadRegistry

use of io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry in project resilience4j by resilience4j.

the class TaggedThreadPoolBulkheadMetricsPublisherTest method customMetricNamesGetApplied.

@Test
public void customMetricNamesGetApplied() {
    MeterRegistry meterRegistry = new SimpleMeterRegistry();
    TaggedThreadPoolBulkheadMetricsPublisher taggedBulkheadMetricsPublisher = new TaggedThreadPoolBulkheadMetricsPublisher(ThreadPoolBulkheadMetricNames.custom().maxThreadPoolSizeMetricName("custom.max.thread.pool.size").coreThreadPoolSizeMetricName("custom.core.thread.pool.size").build(), meterRegistry);
    ThreadPoolBulkheadRegistry bulkheadRegistry = ThreadPoolBulkheadRegistry.of(ThreadPoolBulkheadConfig.ofDefaults(), taggedBulkheadMetricsPublisher);
    bulkhead = bulkheadRegistry.bulkhead("backendA");
    Set<String> metricNames = meterRegistry.getMeters().stream().map(Meter::getId).map(Meter.Id::getName).collect(Collectors.toSet());
    assertThat(metricNames).hasSameElementsAs(EXPECTED_METERS);
}
Also used : Meter(io.micrometer.core.instrument.Meter) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ThreadPoolBulkheadRegistry(io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.Test)

Example 4 with ThreadPoolBulkheadRegistry

use of io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry in project resilience4j by resilience4j.

the class TaggedThreadPoolBulkheadMetricsTest method customMetricNamesGetApplied.

@Test
public void customMetricNamesGetApplied() {
    MeterRegistry meterRegistry = new SimpleMeterRegistry();
    ThreadPoolBulkheadRegistry bulkheadRegistry = ThreadPoolBulkheadRegistry.ofDefaults();
    bulkhead = bulkheadRegistry.bulkhead("backendA");
    TaggedThreadPoolBulkheadMetrics.ofThreadPoolBulkheadRegistry(ThreadPoolBulkheadMetricNames.custom().maxThreadPoolSizeMetricName("custom.max.thread.pool.size").coreThreadPoolSizeMetricName("custom.core.thread.pool.size").build(), bulkheadRegistry).bindTo(meterRegistry);
    Set<String> metricNames = meterRegistry.getMeters().stream().map(Meter::getId).map(Meter.Id::getName).collect(Collectors.toSet());
    assertThat(metricNames).hasSameElementsAs(EXPECTED_METERS);
}
Also used : Meter(io.micrometer.core.instrument.Meter) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ThreadPoolBulkheadRegistry(io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.Test)

Aggregations

ThreadPoolBulkheadRegistry (io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry)4 Meter (io.micrometer.core.instrument.Meter)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 Test (org.junit.Test)2 Requires (io.micronaut.context.annotation.Requires)1 Singleton (javax.inject.Singleton)1 Bean (org.springframework.context.annotation.Bean)1