Check this awesome video. Below you can find how to configure Hystrix with Spring Boot 1.1.8 with Spring Cloud Hystrix Starter.
compile 'org.springframework.cloud:spring-cloud-starter-hystrix:1.0.0.RELEASE' for Spring Boot 1.1.8.
@EnableCircuitBreaker on Main/Runner class
Register Hystrix Servlet:
@Configuration
public class HystrixServletDefinitions {
@Bean(name = "hystrixRegistrationBean")
public ServletRegistrationBean servletRegistrationBean() {
ServletRegistrationBean registration = new ServletRegistrationBean(
new HystrixMetricsStreamServlet(), "/metrics/hystrix.stream");
registration.setName("hystrixServlet");
registration.setLoadOnStartup(1);
return registration;
}
}
- Add it to Spring Security if needed: .antMatchers(“/metrics/hystrix.stream”).permitAll()
- Create config.properties file like this + check docs
- Create defaultMethod which will be used when CircuitBreaker will open:
public List<SampleObject> defaultMethod() {
return Lists.newArrayList();
}
Use annotation where you want to use it:
@HystrixCommand(fallbackMethod = "defaultMethod")
public List<SampleObject> getRealMethod() {
// implementation...
}
Want cool Dashboard? Get and deploy somewhere Hystrix-Dashboard.war and target our “/metrics/hystrix.stream”