2015-12-17 29 views
1

如果我有以下蝟命令: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(); 

如果蝟斷開電路,因爲與「Looong」超時通話,是否意味着通話用「快速」將打開到

回答

1

基本上是隻要雙方擁有相同的命令鍵就像你的例子。但是對於斷路器來說,有更多的條件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; 
} 
+0

謝謝@ahus,所以覺得我可以做somethink像'publicTimeoutDependingOnParam(字符串名稱){超(HystrixCommandGroupKey.Factory.asKey( 「TDPGroup」))andCommandKey(HystrixCommandKey.Factory.asKey(」。 TDP「+ name))); this.name = name;}' – Pleymor

+0

確切地說,應該可以工作。 – ahus1

相關問題