Search in sources :

Example 16 with TimeLimiterRegistry

use of io.github.resilience4j.timelimiter.TimeLimiterRegistry in project resilience4j by resilience4j.

the class TimeLimiterRegistryFactory method timeLimiterRegistry.

@Singleton
@Requires(beans = TimeLimiterConfigurationProperties.class)
public TimeLimiterRegistry timeLimiterRegistry(TimeLimiterConfigurationProperties timeLimiterConfigurationProperties, @TimeLimiterQualifier EventConsumerRegistry<TimeLimiterEvent> timeLimiterEventConsumerRegistry, @TimeLimiterQualifier RegistryEventConsumer<TimeLimiter> timeLimiterRegistryEventConsumer, @TimeLimiterQualifier CompositeCustomizer<TimeLimiterConfigCustomizer> compositeTimeLimiterCustomizer) {
    TimeLimiterRegistry timeLimiterRegistry = createTimeLimiterRegistry(timeLimiterConfigurationProperties, timeLimiterRegistryEventConsumer, compositeTimeLimiterCustomizer);
    registerEventConsumer(timeLimiterRegistry, timeLimiterEventConsumerRegistry, timeLimiterConfigurationProperties);
    initTimeLimiterRegistry(timeLimiterRegistry, timeLimiterConfigurationProperties, compositeTimeLimiterCustomizer);
    return timeLimiterRegistry;
}
Also used : TimeLimiterRegistry(io.github.resilience4j.timelimiter.TimeLimiterRegistry) Requires(io.micronaut.context.annotation.Requires) Singleton(javax.inject.Singleton)

Example 17 with TimeLimiterRegistry

use of io.github.resilience4j.timelimiter.TimeLimiterRegistry in project resilience4j by resilience4j.

the class TimeLimiterMetricsPublisherTest method customMetricNamesOverrideDefaultOnes.

@Test
public void customMetricNamesOverrideDefaultOnes() {
    TimeLimiterMetricsPublisher.MetricNames names = TimeLimiterMetricsPublisher.MetricNames.custom().callsMetricName("custom_calls").build();
    CollectorRegistry customRegistry = new CollectorRegistry();
    TimeLimiterMetricsPublisher timeLimiterMetricsPublisher = new TimeLimiterMetricsPublisher(names);
    timeLimiterMetricsPublisher.register(customRegistry);
    TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.of(TimeLimiterConfig.ofDefaults(), timeLimiterMetricsPublisher);
    TimeLimiter timeLimiter = timeLimiterRegistry.timeLimiter("backendA");
    timeLimiter.onSuccess();
    timeLimiter.onError(new RuntimeException());
    timeLimiter.onError(new TimeoutException());
    Double successfulCalls = getSampleValue(customRegistry, "custom_calls", KIND_SUCCESSFUL);
    Double failedCalls = getSampleValue(customRegistry, "custom_calls", KIND_FAILED);
    Double timeoutCalls = getSampleValue(customRegistry, "custom_calls", KIND_TIMEOUT);
    assertThat(successfulCalls).isNotNull();
    assertThat(failedCalls).isNotNull();
    assertThat(timeoutCalls).isNotNull();
}
Also used : TimeLimiter(io.github.resilience4j.timelimiter.TimeLimiter) TimeLimiterRegistry(io.github.resilience4j.timelimiter.TimeLimiterRegistry) CollectorRegistry(io.prometheus.client.CollectorRegistry) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Aggregations

TimeLimiterRegistry (io.github.resilience4j.timelimiter.TimeLimiterRegistry)17 Test (org.junit.Test)13 TimeLimiter (io.github.resilience4j.timelimiter.TimeLimiter)8 DefaultEventConsumerRegistry (io.github.resilience4j.consumer.DefaultEventConsumerRegistry)2 TimeLimiterConfig (io.github.resilience4j.timelimiter.TimeLimiterConfig)2 TimeLimiterEvent (io.github.resilience4j.timelimiter.event.TimeLimiterEvent)2 Meter (io.micrometer.core.instrument.Meter)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 Requires (io.micronaut.context.annotation.Requires)1 CollectorRegistry (io.prometheus.client.CollectorRegistry)1 TimeoutException (java.util.concurrent.TimeoutException)1 Singleton (javax.inject.Singleton)1