Hystrix Dashboard 介绍
首先我们要明确Hystrix Dashboard是两个概念:Hystrix和Dashboard。
1.Hystrix:SpringCloud中的Hystrix组件,也就是断路器,可以实现服务降级的功能。
定义的服务如果发生错误就可以使用Hystrix定义错误之后的回退。
通常在工程中使用HystrixCommand注解实现,该注解源码如下:
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface HystrixCommand {
String groupKey() default "";
String commandKey() default "";
String threadPoolKey() default "";
String fallbackMethod() default "";
HystrixProperty[] commandProperties() default {};
HystrixProperty[] threadPoolProperties() default {};
Class<? extends Throwable>[] ignoreExceptions() default {};
ObservableExecutionMode observableExecutionMode() default ObservableExecutionMode.EAGER;
HystrixException[] raiseHystrixExceptions() default {};
String defaultFallback() default "";
}
通过@Target({ElementType.METHOD})我们可以知道这个注解是定义在方法上的。其中比较重要的方法是String fallbackMethod() default ""; 它是定义回退方法的名称,这个方法必须和Hystrix执行方法在相同的类中。
以下是一个具体使用的例子:
public SearchResponse fallback(SearchRequest request, Throwable e){
return null;
}
@Override
@HystrixCommand(fallbackMethod =