org.springframework.cloud.client.circuitbreaker.Customizer Java Examples

The following examples show how to use org.springframework.cloud.client.circuitbreaker.Customizer. 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: 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 #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: ReactiveSentinelCircuitBreakerIntegrationTest.java    From spring-cloud-alibaba with Apache License 2.0 6 votes vote down vote up
@Bean
public Customizer<ReactiveSentinelCircuitBreakerFactory> slowCustomizer() {
	return factory -> {
		factory.configure(builder -> builder
				.rules(Collections.singletonList(new DegradeRule("slow_mono")
						.setGrade(RuleConstant.DEGRADE_GRADE_RT).setCount(100)
						.setTimeWindow(5))),
				"slow_mono");
		factory.configure(builder -> builder
				.rules(Collections.singletonList(new DegradeRule("slow_flux")
						.setGrade(RuleConstant.DEGRADE_GRADE_RT).setCount(100)
						.setTimeWindow(5))),
				"slow_flux");
		factory.configureDefault(id -> new SentinelConfigBuilder()
				.resourceName(id)
				.rules(Collections.singletonList(new DegradeRule(id)
						.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
						.setCount(0.5).setTimeWindow(10)))
				.build());
	};
}
 
Example #4
Source File: SentinelCircuitBreakerIntegrationTest.java    From spring-cloud-alibaba with Apache License 2.0 6 votes vote down vote up
@Bean
public Customizer<SentinelCircuitBreakerFactory> slowCustomizer() {
	String slowId = "slow";
	List<DegradeRule> rules = Collections.singletonList(
			new DegradeRule(slowId).setGrade(RuleConstant.DEGRADE_GRADE_RT)
					.setCount(100).setTimeWindow(10));
	return factory -> {
		factory.configure(builder -> builder.rules(rules), slowId);
		factory.configureDefault(id -> new SentinelConfigBuilder()
				.resourceName(id)
				.rules(Collections.singletonList(new DegradeRule(id)
						.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
						.setCount(0.5).setTimeWindow(10)))
				.build());
	};
}
 
Example #5
Source File: MyConfiguration.java    From spring-cloud-alibaba with Apache License 2.0 6 votes vote down vote up
@Bean
public Customizer<ReactiveSentinelCircuitBreakerFactory> slowCustomizer() {
	return factory -> {
		factory.configure(builder -> builder.rules(Collections.singletonList(
				new DegradeRule("slow_mono").setGrade(RuleConstant.DEGRADE_GRADE_RT)
						.setCount(100).setTimeWindow(5))),
				"slow_mono");
		factory.configure(builder -> builder.rules(Collections.singletonList(
				new DegradeRule("slow_flux").setGrade(RuleConstant.DEGRADE_GRADE_RT)
						.setCount(100).setTimeWindow(5))),
				"slow_flux");
		factory.configureDefault(id -> new SentinelConfigBuilder().resourceName(id)
				.rules(Collections.singletonList(new DegradeRule(id)
						.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
						.setCount(0.5).setTimeWindow(10)))
				.build());
	};
}
 
Example #6
Source File: Resilience4JCircuitBreakerIntegrationTest.java    From spring-cloud-circuitbreaker with Apache License 2.0 6 votes vote down vote up
@Bean
public Customizer<Resilience4JCircuitBreakerFactory> slowCustomizer() {
	return factory -> {
		factory.configure(
				builder -> builder
						.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults())
						.timeLimiterConfig(TimeLimiterConfig.custom()
								.timeoutDuration(Duration.ofSeconds(2)).build()),
				"slow");
		factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
				.timeLimiterConfig(TimeLimiterConfig.custom()
						.timeoutDuration(Duration.ofSeconds(4)).build())
				.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()).build());
		factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker
				.getEventPublisher().onError(slowErrorConsumer)
				.onSuccess(slowSuccessConsumer), "slow");
		factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker
				.getEventPublisher().onError(normalErrorConsumer)
				.onSuccess(normalSuccessConsumer), "normal");
	};
}
 
Example #7
Source File: Resilience4JCircuitBreaker.java    From spring-cloud-circuitbreaker with Apache License 2.0 5 votes vote down vote up
public Resilience4JCircuitBreaker(String id,
		io.github.resilience4j.circuitbreaker.CircuitBreakerConfig circuitBreakerConfig,
		TimeLimiterConfig timeLimiterConfig,
		CircuitBreakerRegistry circuitBreakerRegistry,
		ExecutorService executorService,
		Optional<Customizer<io.github.resilience4j.circuitbreaker.CircuitBreaker>> circuitBreakerCustomizer) {
	this.id = id;
	this.circuitBreakerConfig = circuitBreakerConfig;
	this.registry = circuitBreakerRegistry;
	this.timeLimiterConfig = timeLimiterConfig;
	this.executorService = executorService;
	this.circuitBreakerCustomizer = circuitBreakerCustomizer;
}
 
Example #8
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 #9
Source File: SpringCloudCircuitBreakerResilience4JFilterFactoryTests.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Bean
public Customizer<ReactiveResilience4JCircuitBreakerFactory> slowCusomtizer() {
	return factory -> {
		factory.addCircuitBreakerCustomizer(
				cb -> cb.transitionToForcedOpenState(), "failcmd");
	};
}
 
Example #10
Source File: ServiceApplication.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@Bean
public Customizer<SentinelCircuitBreakerFactory> defaultConfig() {
	return factory -> {
		factory.configureDefault(
				id -> new SentinelConfigBuilder().resourceName(id)
						.rules(Collections.singletonList(new DegradeRule(id)
								.setGrade(RuleConstant.DEGRADE_GRADE_RT).setCount(100)
								.setTimeWindow(10)))
						.build());
	};
}
 
Example #11
Source File: ReactiveResilience4JCircuitBreakerIntegrationTest.java    From spring-cloud-circuitbreaker with Apache License 2.0 5 votes vote down vote up
@Bean
public Customizer<ReactiveResilience4JCircuitBreakerFactory> slowCusomtizer() {
	return factory -> {
		factory.configureDefault(
				id -> new Resilience4JConfigBuilder(id)
						.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults())
						.timeLimiterConfig(TimeLimiterConfig.custom()
								.timeoutDuration(Duration.ofSeconds(4)).build())
						.build());
		factory.configure(
				builder -> builder
						.timeLimiterConfig(TimeLimiterConfig.custom()
								.timeoutDuration(Duration.ofSeconds(2)).build())
						.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()),
				"slow", "slowflux");
		factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker
				.getEventPublisher().onError(slowErrorConsumer)
				.onSuccess(slowSuccessConsumer), "slow");
		factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker
				.getEventPublisher().onError(normalErrorConsumer)
				.onSuccess(normalSuccessConsumer), "normal");
		factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker
				.getEventPublisher().onError(slowFluxErrorConsumer)
				.onSuccess(slowFluxSuccessConsumer), "slowflux");
		factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker
				.getEventPublisher().onError(normalFluxErrorConsumer)
				.onSuccess(normalFluxSuccessConsumer), "normalflux");
	};
}
 
Example #12
Source File: ReactiveHystrixCircuitbreakerDemoApplication.java    From spring-cloud-circuitbreaker-demo with Apache License 2.0 5 votes vote down vote up
@Bean
public Customizer<ReactiveHystrixCircuitBreakerFactory> defaultConfig() {
	return factory -> factory.configureDefault(id -> {
		return HystrixObservableCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(id))
				.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
						.withExecutionTimeoutInMilliseconds(3000));

	});
}
 
Example #13
Source File: ReactiveResilience4JCircuitBreaker.java    From spring-cloud-circuitbreaker with Apache License 2.0 5 votes vote down vote up
public ReactiveResilience4JCircuitBreaker(String id,
		Resilience4JConfigBuilder.Resilience4JCircuitBreakerConfiguration config,
		CircuitBreakerRegistry circuitBreakerRegistry,
		Optional<Customizer<CircuitBreaker>> circuitBreakerCustomizer) {
	this.id = id;
	this.config = config;
	this.registry = circuitBreakerRegistry;
	this.circuitBreakerCustomizer = circuitBreakerCustomizer;
}
 
Example #14
Source File: SpringRetryCircuitBreaker.java    From spring-cloud-circuitbreaker with Apache License 2.0 5 votes vote down vote up
public SpringRetryCircuitBreaker(String id,
		SpringRetryConfigBuilder.SpringRetryConfig config,
		Optional<Customizer<RetryTemplate>> retryTemplateCustomizer) {
	this.id = id;
	this.config = config;
	this.retryTemplateCustomizer = retryTemplateCustomizer;
	this.retryTemplate = new RetryTemplate();
}
 
Example #15
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 #16
Source File: ReactiveResilience4JCircuitbreakerDemoApplication.java    From spring-cloud-circuitbreaker-demo with Apache License 2.0 5 votes vote down vote up
@Bean
public Customizer<ReactiveResilience4JCircuitBreakerFactory> defaultCustomizer() {
	CircuitBreakerRegistry cbr = CircuitBreakerRegistry.ofDefaults();
	return factory -> {
		factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
				.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults())
				.timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(3)).build())
				.circuitBreakerConfig(CircuitBreakerConfig.custom().failureRateThreshold(10)
						.slowCallRateThreshold(5).slowCallRateThreshold(2).build()).build());
	};
}
 
Example #17
Source File: ReactiveResilience4JCircuitBreakerFactory.java    From spring-cloud-circuitbreaker with Apache License 2.0 4 votes vote down vote up
public void addCircuitBreakerCustomizer(Customizer<CircuitBreaker> customizer,
		String... ids) {
	for (String id : ids) {
		circuitBreakerCustomizers.put(id, customizer);
	}
}
 
Example #18
Source File: Resilience4JCircuitBreakerFactory.java    From spring-cloud-circuitbreaker with Apache License 2.0 4 votes vote down vote up
public void addCircuitBreakerCustomizer(Customizer<CircuitBreaker> customizer,
		String... ids) {
	for (String id : ids) {
		circuitBreakerCustomizers.put(id, customizer);
	}
}
 
Example #19
Source File: SpringRetryCircuitBreakerFactory.java    From spring-cloud-circuitbreaker with Apache License 2.0 4 votes vote down vote up
public void addRetryTemplateCustomizers(Customizer<RetryTemplate> customizer,
		String... ids) {
	for (String id : ids) {
		this.retryTemplateCustomizers.put(id, customizer);
	}
}
 
Example #20
Source File: HystrixCircuitbreakerDemoApplication.java    From spring-cloud-circuitbreaker-demo with Apache License 2.0 4 votes vote down vote up
@Bean
public Customizer<HystrixCircuitBreakerFactory> defaultConfig() {
	return factory -> factory.configureDefault(id -> HystrixCommand.Setter
			.withGroupKey(HystrixCommandGroupKey.Factory.asKey(id))
			.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(3000)));
}
 
Example #21
Source File: SpringCloudCircuitbreakerDemoReactiveApplication.java    From spring-cloud-circuitbreaker-demo with Apache License 2.0 4 votes vote down vote up
@Bean
public Customizer<ReactiveResilience4JCircuitBreakerFactory> defaultCustomizer() {
	return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
			.circuitBreakerConfig(CircuitBreakerConfig.ofDefaults())
			.timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(3)).build()).build());
}