Hystrix & Spring Boot Configuration

Check this awesome video. Below you can find how to configure Hystrix with Spring Boot 1.1.8 with Spring Cloud Hystrix Starter.

  1. compile ‘org.springframework.cloud:spring-cloud-starter-hystrix:1.0.0.RELEASE’ for Spring Boot 1.1.8.
  2. @EnableCircuitBreaker on Main/Runner class
  3. 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;
           }
    }
    
  4. Add it to Spring Security if needed: .antMatchers(“/metrics/hystrix.stream”).permitAll()
  5. Create config.properties file like this  + check docs
  6. Create defaultMethod which will be used when CircuitBreaker will open:
    public List<SampleObject> defaultMethod() {
                 return Lists.newArrayList();
           }
    
  7. Use annotation where you want to use it:
    @HystrixCommand(fallbackMethod = "defaultMethod")
           public List<SampleObject> getRealMethod() {
                 // implementation...
           }
  8. Want cool Dashboard? Get and deploy somewhere Hystrix-Dashboard.war and target our “/metrics/hystrix.stream”
  9. See some annoying messages in console?
    1. Set in main class System.setProperty(“spring.cloud.bootstrap.enabled”, “false”);
    2. add to application.properties: spring.application.name=YourAppName
  10. I guess with this solution you will get a lot of jars which are not needed at all
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s