Hystrix 是否能够根据方法参数打开电路?

Is Hystrix able to open a circuit depending on method parameters?

如果我有以下 Hystrix 命令:

public class TimeoutDependingOnParam extends HystrixCommand<String> {

    private final String name;

    public TimeoutDependingOnParam (String name) {
        super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
        this.name = name;
    }

    @Override
    protected String run() {

        if (name.equals("Looong")) {
           waitABillionYears();
        }

        return "Hello " + name + "!";
    }
}

呼叫者:

// no timeout for "Quick"
String s1 = new TimeoutDependingOnParam("Quick").execute();

// timeout for "Looong"
String s2 = new TimeoutDependingOnParam("Looong").execute();

如果Hystrix因为"Looong"的调用超时而打开了电路,是否意味着"Quick"的调用将被打开到

基本上是的,只要两者都像您的示例中一样具有相同的命令键。但是断路器打开还有更多的条件as stated in the documentation about the Circuit Breaker.

您可以实现两个不同的命令,或者根据参数在构造函数中设置 CommandKey。 This is an extract from the documentation:

public CommandHelloWorld(String name) {
    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
            .andCommandKey(HystrixCommandKey.Factory.asKey("HelloWorld")));
    this.name = name;
}