hystrix实战之javanica

spingboot2.0.3集成hystrix的,访问dashboard的另外一种方式:

https://blog.csdn.net/qq_38455201/article/details/80783410

这种方式不需要在application中添加下面的内容:

第二种方式:

使用下面的方式可以直接访问:http://localhost:8011/hystrix.stream

@Bean
public ServletRegistrationBean getServlet() {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}

自定义hystrix:

不管什么方式,hystrix的返回类型和参数都要和方法一致,即使是自定义的hystrixCommand也是这样的。

使用HystrixCommand,但是我们在开发中都已经分好了各种业务的servie,如何套入这个Hystrix?

https://www.jianshu.com/p/77d95dc57584

https://www.cnblogs.com/cowboys/p/7655829.html

https://blog.csdn.net/sdmjhca/article/details/77948511

https://segmentfault.com/a/1190000011006552

https://www.jianshu.com/p/189e6675fb28

大部分场景下使用默认属性即可,不需要配置那么多属性,更多的属性可以参考:https://github.com/Netflix/Hystrix/wiki/Configuration
 
属性这么多紧接着就有一个问题:我们是否需要为每一个需要使用hystrix方法都定义一遍属性?
比如:一个类中有很多方法,不能在每个方法都配置一遍相同的属性,容易造成配置代码的冗余;所以Javanica提供了@DefaultProperties注解,解释如下:
 
@DefaultProperties是类(类型)级别的注释,允许默认命令属性,如groupKey,threadPoolKey,commandProperties,threadPoolProperties,ignoreExceptions和raiseHystrixExceptions。 
使用此注解指定的属性,将在类中使用@HystrixCommand注解的方法中公用,除非某个方法明确使用相应的@HystrixCommand参数来指定这些属性。
原文地址:https://www.cnblogs.com/fengli9998/p/9322995.html