hystrix如何配置configuration——线程模式、超时时间等等

主要参考:

在官网的说明上能够看到,有很多的参数配置,那么如何实现自定义的参数配置呢。官网上给出了说明。

官网上的说明是这样的
You can define an instance-specific default. Example:
public HystrixCommandInstance(int id) {
    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
        .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
               .withExecutionTimeoutInMilliseconds(500)));
    this.id = id;
}
There are convenience constructors for commonly-set initial values. Here's an example:
public HystrixCommandInstance(int id) {
    super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"), 500);
    this.id = id;
}
下面是自己的方式写的一个配置信息。需要注意的是继承hystrixCommand的类的构造函数应该是这样的:
public CommandHelloworld(Setter setter, String name) {
    super(setter);
    this.name = name;
}
然后调用的例子如下:
String s = new CommandHelloworld(HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
        .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey("threadpool2"))
        .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
                .withExecutionTimeoutInMilliseconds(500))
        , "ccc").execute();
System.out.println(s);

猜你喜欢

转载自blog.csdn.net/wild46cat/article/details/80781785