Created
October 23, 2014 01:15
-
-
Save maxtomassi/42b73309e1ecc7634785 to your computer and use it in GitHub Desktop.
Circuit breaker example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CircuitBreakerCommand extends HystrixCommand<String>{ | |
| private final String message; | |
| public CircuitBreakerCommand(String message) { | |
| super(HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("MyGroup")) | |
| .andCommandPropertiesDefaults( | |
| HystrixCommandProperties.Setter() | |
| .withCircuitBreakerEnabled(true) | |
| .withCircuitBreakerRequestVolumeThreshold(5) | |
| )); | |
| this.message = message; | |
| } | |
| @Override | |
| protected String run() { | |
| delay(500); | |
| System.out.println("Circuit open? > " + this.isCircuitBreakerOpen()); | |
| throw new RuntimeException("Failed!"); | |
| } | |
| private void delay(int millis) { | |
| try { | |
| Thread.sleep(millis); | |
| } catch (InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| @Override | |
| protected String getFallback() { | |
| return "Hello Fallback"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment