org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JCircuitBreakerFactory Java Examples

The following examples show how to use org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JCircuitBreakerFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CircuitBreakerTests.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
@Test
public void should_pass_tracing_information_when_using_circuit_breaker() {
	// given
	Tracer tracer = this.tracer;
	ScopedSpan scopedSpan = null;
	try {
		scopedSpan = tracer.startScopedSpan("start");
		// when
		Span span = new Resilience4JCircuitBreakerFactory().create("name")
				.run(new TraceSupplier<>(tracer, tracer::currentSpan));

		then(span).isNotNull();
		then(scopedSpan.context().traceIdString())
				.isEqualTo(span.context().traceIdString());
	}
	finally {
		scopedSpan.finish();
	}
}
 
Example #2
Source File: SpringApp.java    From tutorials with MIT License 6 votes vote down vote up
@Bean
public Customizer<Resilience4JCircuitBreakerFactory> globalCustomConfiguration() {
    TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom()
            .timeoutDuration(Duration.ofSeconds(4))
            .build();
    CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom()
            .failureRateThreshold(50)
            .waitDurationInOpenState(Duration.ofMillis(1000))
            .slidingWindowSize(2)
            .build();

    return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
            .timeLimiterConfig(timeLimiterConfig)
            .circuitBreakerConfig(circuitBreakerConfig)
            .build());
}
 
Example #3
Source File: SpringApp.java    From tutorials with MIT License 6 votes vote down vote up
@Bean
public Customizer<Resilience4JCircuitBreakerFactory> specificCustomConfiguration2() {

    TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom()
            .timeoutDuration(Duration.ofSeconds(4))
            .build();
    CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom()
            .failureRateThreshold(50)
            .waitDurationInOpenState(Duration.ofMillis(1000))
            .slidingWindowSize(2)
            .build();

    return factory -> factory.configure(builder -> builder.circuitBreakerConfig(circuitBreakerConfig)
                    .timeLimiterConfig(timeLimiterConfig).build(),
            "circuitBreaker1", "circuitBreaker2", "circuitBreaker3");
}
 
Example #4
Source File: Resilience4JCircuitbreakerDemoApplication.java    From spring-cloud-circuitbreaker-demo with Apache License 2.0 5 votes vote down vote up
@Bean
public Customizer<Resilience4JCircuitBreakerFactory> defaultCustomizer() {
	return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
			.timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(3)).build())
			.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults())
			.build());
}
 
Example #5
Source File: CircuitBreakerTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void should_pass_tracing_information_when_using_circuit_breaker_with_fallback() {
	// given
	Tracer tracer = this.tracer;
	AtomicReference<Span> first = new AtomicReference<>();
	AtomicReference<Span> second = new AtomicReference<>();
	ScopedSpan scopedSpan = null;
	try {
		scopedSpan = tracer.startScopedSpan("start");
		// when
		BDDAssertions.thenThrownBy(() -> new Resilience4JCircuitBreakerFactory()
				.create("name").run(new TraceSupplier<>(tracer, () -> {
					first.set(tracer.currentSpan());
					throw new IllegalStateException("boom");
				}), new TraceFunction<>(tracer, throwable -> {
					second.set(tracer.currentSpan());
					throw new IllegalStateException("boom2");
				}))).isInstanceOf(IllegalStateException.class)
				.hasMessageContaining("boom2");

		then(this.spans).hasSize(2);
		then(scopedSpan.context().traceIdString())
				.isEqualTo(first.get().context().traceIdString());
		then(scopedSpan.context().traceIdString())
				.isEqualTo(second.get().context().traceIdString());
		then(first.get().context().spanIdString())
				.isNotEqualTo(second.get().context().spanIdString());

		MutableSpan reportedSpan = this.spans.get(1);
		then(reportedSpan.name()).contains("CircuitBreakerTests");
		then(reportedSpan.tags().get("error")).contains("boom2");
	}
	finally {
		scopedSpan.finish();
	}
}
 
Example #6
Source File: SpringApp.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public Customizer<Resilience4JCircuitBreakerFactory> specificCustomConfiguration1() {

    TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom()
            .timeoutDuration(Duration.ofSeconds(4))
            .build();
    CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom()
            .failureRateThreshold(50)
            .waitDurationInOpenState(Duration.ofMillis(1000))
            .slidingWindowSize(2)
            .build();

    return factory -> factory.configure(builder -> builder.circuitBreakerConfig(circuitBreakerConfig)
            .timeLimiterConfig(timeLimiterConfig).build(), "circuitBreaker");
}
 
Example #7
Source File: BottlingConfiguration.java    From brewery with Apache License 2.0 4 votes vote down vote up
@Bean
Resilience4JCircuitBreakerFactory resilience4JCircuitBreakerFactory() {
    return new Resilience4JCircuitBreakerFactory();
}
 
Example #8
Source File: CircuitBreakerIntegrationTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
Resilience4JCircuitBreakerFactory resilience4JCircuitBreakerFactory() {
	return new Resilience4JCircuitBreakerFactory();
}