Java Code Examples for io.github.resilience4j.circuitbreaker.CircuitBreaker#transitionToForcedOpenState()
The following examples show how to use
io.github.resilience4j.circuitbreaker.CircuitBreaker#transitionToForcedOpenState() .
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: CircuitBreakerEndpoint.java From resilience4j with Apache License 2.0 | 6 votes |
@WriteOperation public CircuitBreakerUpdateStateResponse updateCircuitBreakerState(@Selector String name, UpdateState updateState) { final CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker(name); final String message = "%s state has been changed successfully"; switch (updateState) { case CLOSE: circuitBreaker.transitionToClosedState(); return createCircuitBreakerUpdateStateResponse(name, circuitBreaker.getState().toString(), String.format(message, name)); case FORCE_OPEN: circuitBreaker.transitionToForcedOpenState(); return createCircuitBreakerUpdateStateResponse(name, circuitBreaker.getState().toString(), String.format(message, name)); case DISABLE: circuitBreaker.transitionToDisabledState(); return createCircuitBreakerUpdateStateResponse(name, circuitBreaker.getState().toString(), String.format(message, name)); default: return createCircuitBreakerUpdateStateResponse(name, circuitBreaker.getState().toString(), "State change value is not supported please use only " + Arrays.toString(UpdateState.values())); } }
Example 2
Source File: CircuitBreakerManager.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
private CircuitBreakerCoalition createCircuitBreaker(String ruleName, CircuitBreakerRule rule) { if (rule == null) { return null; } if (rule.getEnabled() != null && rule.getEnabled() && rule.getFailureRateThreshold() != null) { try { CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom() .failureRateThreshold(rule.getFailureRateThreshold()) .waitDurationInOpenState(rule.getWaitDurationInOpenState()) .ringBufferSizeInHalfOpenState(rule.getRingBufferSizeInHalfOpenState()) .ringBufferSizeInClosedState(rule.getRingBufferSizeInClosedState()) .build(); CircuitBreaker circuitBreaker = CircuitBreaker.of(ruleName, circuitBreakerConfig); if (rule.getForceOpen() != null && rule.getForceOpen()) { circuitBreaker.transitionToForcedOpenState(); } CircuitBreakerCoalition circuitBreakerCoalition = new CircuitBreakerCoalition( circuitBreaker, rule); return circuitBreakerCoalition; } catch (Throwable e) { logger.error("failed to create circuitBreaker,name:{},id{}", ruleName, rule.getRuleId(), e); return null; } } return null; }