一 为了让Turbine监控2个以上的微服务,先建一个项目microservice-consumer-movie-feign-hystrix-fallback-stream,确保该项目的application.yml配置如下
server:
port: 8020
spring:
application:
name: microservice-consumer-movie-feign-hystrix-fallback-stream
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
prefer-ip-address: true
二 创建一个Maven项目,项目名为microservice-hystrix-turbine,并为项目添加以下依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
三 在启动类上添加注解@EnableTurbine
package com.itmuch.cloud.study;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
@SpringBootApplication
@EnableTurbine
public class TurbineApplication {
public static void main(String[] args) {
SpringApplication.run(TurbineApplication.class, args);
}
}
四 编写配置文件application.yml
server:
port: 8031
spring:
application:
name: microservice-hystrix-turbine
eureka:
client:
service-url:
defaultZone:http://localhost:8761/eureka/
instance:
prefer-ip-address: true
turbine:
appConfig: microservice-consumer-movie,microservice-consumer-movie-feign-hystrix-fallback-stream
clusterNameExpression: "'default'"
使用以上配置,Turbine会在Eureka Server中找到microservice-consumer-movie和microservice-consumer-movie-feign-hystrix-fallback-stream这两个微服务,并聚合这两个微服务的监控数据
五 测试
1 启动eureka
2 启动user微服务
3 启动项目microservice-consumer-movie-ribbon-hystrix
4 启动项目microservice-consumer-movie-feign-hystrix-fallback-stream
5 启动项目microservice-hystrix-turbine
6 启动项目microservice-hystrix-dashboard
7 观察eureka
8 访问
http://localhost:8010/user/1,让microservice-consumer-movie-ribbon-hystrix微服务产生监控数据
9 访问
http://localhost:8020/user/1,让microservice-consumer-movie-feign-hystrix-fallback-stream微服务产生监控数据
10 打开
http://localhost:8030/hystrix,进入Hystrix Dashboard首页,在URL地址栏输入
http://localhost:8031/turbine.stream,然后点击监控按钮,得到如下界面: