sc-sc - 云代码空间
——
我们在熔断示例项目spring-cloud-consumer-hystrix的基础上更改,重新命名为:spring-cloud-consumer-hystrix-dashboard。
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
这三个包必须添加
启动类添加启用Hystrix Dashboard和熔断器
@SpringBootApplication @EnableDiscoveryClient @EnableFeignClients @EnableHystrixDashboard @EnableCircuitBreaker public class ConsumerApplication { public static void main(String[] args) { SpringApplication.run(ConsumerApplication.class, args); } }
在复杂的分布式系统中,相同服务的节点经常需要部署上百甚至上千个,很多时候,运维人员希望能够把相同服务的节点状态以一个整体集群的形式展现出来,这样可以更好的把握整个系统的状态。 为此,Netflix提供了一个开源项目(Turbine)来提供把多个hystrix.stream的内容聚合为一个数据源供Dashboard展示。
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-turbine</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-netflix-turbine</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId> </dependency> </dependencies>
spring.application.name=hystrix-dashboard-turbine server.port=8001 turbine.appConfig=node01,node02 turbine.aggregator.clusterConfig= default turbine.clusterNameExpression= new String("default") eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
启动类添加@EnableTurbine,激活对Turbine的支持
@SpringBootApplication @EnableHystrixDashboard @EnableTurbine public class DashboardApplication { public static void main(String[] args) { SpringApplication.run(DashboardApplication.class, args); } }
到此Turbine(hystrix-dashboard-turbine)配置完成
在示例项目spring-cloud-consumer-hystrix基础上修改为两个服务的调用者spring-cloud-consumer-node1和spring-cloud-consumer-node2
spring-cloud-consumer-node1项目改动如下: application.properties文件内容
spring.application.name=node01 server.port=9001 feign.hystrix.enabled=true eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
spring-cloud-consumer-node2项目改动如下: application.properties文件内容
spring.application.name=node02 server.port=9002 feign.hystrix.enabled=true eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
HelloRemote类修改:
@FeignClient(name= "spring-cloud-producer2", fallback = HelloRemoteHystrix.class) public interface HelloRemote { @RequestMapping(value = "/hello") public String hello2(@RequestParam(value = "name") String name); }
对应的HelloRemoteHystrix和ConsumerController类跟随修改,具体查看代码
修改完毕后,依次启动spring-cloud-eureka、spring-cloud-consumer-node1、spring-cloud-consumer-node1、hystrix-dashboard-turbine(Turbine)
打开eureka后台可以看到注册了三个服务:
访问 http://localhost:8001/turbine.stream
返回:
: ping
data: {"reportingHostsLast10Seconds":1,"name":"meta","type":"meta","timestamp":1494921985839}
并且会不断刷新以获取实时的监控数据,说明和单个的监控类似,返回监控项目的信息。进行图形化监控查看,输入:http://localhost:8001/hystrix,返回酷酷的小熊界面,输入: http://localhost:8001/turbine.stream,然后点击 Monitor Stream ,可以看到出现了俩个监控列表
Spring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码请加企鹅求求:yuncode.net