Skip to content

Instantly share code, notes, and snippets.

@maxtomassi
Created October 23, 2014 01:15
Show Gist options
  • Select an option

  • Save maxtomassi/42b73309e1ecc7634785 to your computer and use it in GitHub Desktop.

Select an option

Save maxtomassi/42b73309e1ecc7634785 to your computer and use it in GitHub Desktop.
Circuit breaker example
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