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

The following examples show how to use org.springframework.cloud.client.circuitbreaker.Customizer. These examples are extracted from open source projects. 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
@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 2
Source Project: spring-cloud-alibaba   Source File: MyConfiguration.java    License: 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 3
@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 4
@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 5
Source Project: tutorials   Source File: SpringApp.java    License: 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 6
Source Project: tutorials   Source File: SpringApp.java    License: 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 7
@Bean
public Customizer<ReactiveHystrixCircuitBreakerFactory> defaultConfig() {
	return factory -> factory.configureDefault(id -> {
		return HystrixObservableCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(id))
				.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
						.withExecutionTimeoutInMilliseconds(3000));

	});
}
 
Example 8
@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 9
@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 10
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 11
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 12
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 13
@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 14
Source Project: spring-cloud-alibaba   Source File: ServiceApplication.java    License: 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 15
@Bean
public Customizer<ReactiveResilience4JCircuitBreakerFactory> slowCusomtizer() {
	return factory -> {
		factory.addCircuitBreakerCustomizer(
				cb -> cb.transitionToForcedOpenState(), "failcmd");
	};
}
 
Example 16
Source Project: tutorials   Source File: SpringApp.java    License: 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 17
@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());
}
 
Example 18
@Bean
public Customizer<HystrixCircuitBreakerFactory> defaultConfig() {
	return factory -> factory.configureDefault(id -> HystrixCommand.Setter
			.withGroupKey(HystrixCommandGroupKey.Factory.asKey(id))
			.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(3000)));
}
 
Example 19
public void addRetryTemplateCustomizers(Customizer<RetryTemplate> customizer,
		String... ids) {
	for (String id : ids) {
		this.retryTemplateCustomizers.put(id, customizer);
	}
}
 
Example 20
public void addCircuitBreakerCustomizer(Customizer<CircuitBreaker> customizer,
		String... ids) {
	for (String id : ids) {
		circuitBreakerCustomizers.put(id, customizer);
	}
}
 
Example 21
public void addCircuitBreakerCustomizer(Customizer<CircuitBreaker> customizer,
		String... ids) {
	for (String id : ids) {
		circuitBreakerCustomizers.put(id, customizer);
	}
}