关闭Hystrix功能

问题描述 投票:7回答:5

我正在将Hystrix集成到一个应用程序中。该应用程序已经投入生产,我们将在沙盒中测试hystrix集成工作,然后再将其推向生产阶段。我的问题是,有没有办法使用一些配置设置打开/关闭hystrix功能?

hystrix
5个回答
7
投票

没有单一的设置。您需要设置多个参数才能禁用Hystrix。

有关配置选项,请参阅https://github.com/Netflix/Hystrix/wiki/Configuration

hystrix.command.default.execution.isolation.strategy=SEMAPHORE
hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests=100000 # basically 'unlimited'
hystrix.command.default.execution.timeout.enabled=false 
hystrix.command.default.circuitBreaker.enabled=false
hystrix.command.default.fallback.enabled=false

请仔细检查您的Hystrix版本以获取可用参数。


4
投票

这就是你所需要的:

# Disable Circuit Breaker (Hystrix)

spring:
  cloud:
    circuit:
      breaker:
        enabled: false

hystrix:
  command:
    default:
      circuitBreaker:
        enabled: false

2
投票

正如ahus1所说,没有一种方法可以完全禁用Hystrix。要在我们的应用程序中禁用它,我们认为将HystrixCommand放在包装类中是最干净和最安全的,并且该包装类只暴露了我们使用的HystrixCommand的部分(在我们的例子中,是execute()方法)。在构造包装类时,我们传递一个包含我们想要执行的代码的Callable,如果Hystrix被禁用(根据我们自己的配置值),我们只需调用Callable而不创建HystrixCommand。这样可以避免执行任何Hystrix代码,并且更容易说Hystrix在禁用时根本不会影响我们的应用程序。


0
投票

如果您的项目是spring Managed,您可以在applicationContext.xml中注释hystrixAspect的bean定义注释以下行

bean id =“hystrixAspect”class =“com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect”/>

这将从您的项目中删除Hystrix。


0
投票

有几种方法可以达到这个目的 -

  1. 为您的每个组执行此操作,包括默认组。虽然这不会禁用hystrix(它只会让电路一直保持关闭状态)但你会达到同样的效果 - hystrix.command.{group-key}.circuitBreaker.forceClosed=false
  2. 如果您使用的是java,则可以创建一个关于@HystrixCommand注释的around建议,并根据标志绕过hystrix执行。

#2的Java代码

@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;
}

0
投票

我遇到了这种情况,我想用一个属性完全关闭Hystrix(我们使用IBM uDeploy来管理动态属性)。我们正在使用建立在Hystrix之上的javanica库

  1. 创建一个用于创建HystrixCommandAspect的Configuration类



@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"));
  }

 }
© www.soinside.com 2019 - 2024. All rights reserved.