Spring Cloud-hystrix Dashboard(八)
单机模式
1.创建一个dashboard项目
2.引入依赖
<!--histrix依赖--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <!--dashboard依赖--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> <!--端点依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
3.在主类上打上注解@EnableHystrixDashboard开启dashboard
@SpringBootApplication @EnableHystrixDashboard public class SpringCloudDashboardApplication { public static void main(String[] args) { SpringApplication.run(SpringCloudDashboardApplication.class, args); } }
4.配置文件配置应用名字和端口
spring: application: name: hystrix-dashboard server: port: 2001
5.启动访问http://127.0.0.1:2001/hystrix
6.在consumer增加hystirx端点的Servlet
/** * 用于开启histrix 端点 用于dashboard图形化 */ @Configuration public class HystrixStreamServletConfig { @Bean public ServletRegistrationBean getServlet() { HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet); registrationBean.setLoadOnStartup(1); registrationBean.addUrlMappings("/actuator/hystrix.stream"); registrationBean.setName("HystrixMetricsStreamServlet"); return registrationBean; } }
7.访问http://127.0.0.1:9001/actuator/hystrix.stream 出现以下内容表示成功 将连接粘贴到仪表盘 开启分析
8.将连接粘贴到仪表盘 开启监控和分析
9.访问一个hystrix请求将会出现监控页面
Turbine集群模式
1.创建一个Turbine项目
2.添加依赖
<!--<!–实现hystrix集群监控依赖–>--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-turbine</artifactId> <version>2.0.1.RELEASE</version> </dependency>
3.开启turbine自动化配置和注册中心服务发现的功能 turbine里面依赖eurekaClient
SpringBootApplication @EnableTurbine//启用turbine @EnableDiscoveryClient //开启服务发现 public class SpringCloudTurbineApplication { public static void main(String[] args) { SpringApplication.run(SpringCloudTurbineApplication.class, args); } }
4.配置文件配置
spring: application: name: trubine #http://localhost:9090/turbine.stream server: port: 9090 eureka: client: serviceUrl: defaultZone: http://peer1:1111/eureka,http://localhost:peer2/eureka turbine: app-config: consumer #监控的服务名 多个,号隔开 cluster-name-expression: new String('default') #指定集群的名称为default 当服务非常多turbine可以启动多个turbine构建集群 具体书194页 combine-host-port: true #可以通过主机名和端口名组合来进行区分
5.打包2个consumer并启动
6.在hystirx仪表盘配置监听trubine连接http://localhost:9090/turbine.stream
基于消息代理
整合MQ
测试失败