【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
继续上一篇,接下来Springcloud配置Hystrix Dashboard监控断路器。
1、添加依赖
在open-feign的pom文件添加依赖,如下
<!--Hystrix Dashboard--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> <!--结合Hystrix Dashboard一同使用查看监控--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
2、启动类
在open-feign模块添加启动类
@EnableHystrixDashboard
3、配置类
@Configuration public class HystrixConfig { // 开启hystrix超时时间,默认1000ms,如今为4000ms @Bean public Customizer<HystrixCircuitBreakerFactory> defaultConfig() { return factory -> factory.configureDefault(id -> HystrixCommand.Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey(id)) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() .withExecutionTimeoutInMilliseconds(4000))); } }
4、启动项目
运行eureka-server,open-feign,
访问路径:http://localhost:8076/hystrix ,出现如图:
然后图中路径我们写:http://localhost:8076/actuator/hystrix.stream
然后点击Monitor Stream 进去之后其实我们是什么都没有的,你要先调用以下接口,http://localhost:8076/test1,
然后在另外一个页面访问路径:http://localhost:8076/actuator/hystrix.stream
这个时候你就能看到下面一直ping的信息,否则只有ping,其他的什么都没有。
最后在点击Monitor Stream进去,如下:
最后差不多,我们就入门成功了,不过每个一段时间就会报错,如下,这个目前没有解决掉,不知道是什么原因,如果有知道的话,评论一下,我改掉,不过无伤大雅,我们的能测试以及运行。
其他成功的。
来源:oschina
链接:https://my.oschina.net/mdxlcj/blog/3141693