Turn off Hystrix functionality

Viewed 17291

I am integrating Hystrix in an application. That application is already in production and we will be testing out hystrix integration work in sandbox before we will push it to production. My question is that is there any way to turn on/off hystrix functionality using some configuration setting?

7 Answers

This is all what you need:

# Disable Circuit Breaker (Hystrix)

spring:
  cloud:
    circuit:
      breaker:
        enabled: false

hystrix:
  command:
    default:
      circuitBreaker:
        enabled: false

There are a couple of ways to achieve this-

  1. Doing this for your every group including default. Although this will not disable hystrix(it will only keep the circuit closed all the time) but you will achieve the same result-

    hystrix.command.{group-key}.circuitBreaker.forceClosed=false

  2. If you are using java, you can create an around advice over @HystrixCommand annotation and bypass hystrix execution based upon a flag.

Java Code for #2-

@Pointcut("@annotation(com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand)")
public void hystrixCommandAnnotationPointcut() {
}

@Around("hystrixCommandAnnotationPointcut()")
public Object methodsAnnotatedWithHystrixCommand(final ProceedingJoinPoint joinPoint) throws Throwable {
Object result = null;
Method method = AopUtils.getMethodFromTarget(joinPoint);
if ((System.getProperty(enable.hystrix).equals("true")) {
    result = joinPoint.proceed();
} else {
    result = method.invoke(joinPoint.getTarget(), joinPoint.getArgs());
}
    return result;
}

I ran into this situation where I wanted to completely turnoff Hystrix using a single property (We use IBM uDeploy to manage dynamic properties). We are using javanica library built on top of Hystrix

  1. Create a Configuration class which creates the HystrixCommandAspect

@Configuration public class HystrixConfiguration{

@Bean(name = "hystrixCommandAspect")
@Conditional(HystrixEnableCondition.class)
public HystrixCommandAspect hystrixCommandAspect(){ 
      return new HystrixCommandAspect()}
}

2. And the conditional class would be enabled based on a system property.

public class HystrixEnableCondition implements Condition{ @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata){ return "YES".equalsIgnoreCase( context.getEnvironment().getProperty("circuitBreaker.enabled")) || "YES".equalsIgnoreCase( System.getProperty("circuitBreaker.enabled")); } }

setting hystrix.command.default.execution.isolation.strategy=SEMAPHORE is enough. Additionally you may or should disable also the timeout threads with hystrix.command.default.execution.timeout.enabled=false

Related