1.在platform下创建模块hystrix-dashboard
2. pom配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>foodie-cloud</artifactId>
<groupId>com.imooc</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hystrix-dashboard</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.imooc.HystrixDashboardApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
3. application.yml
平台组件的端口往后移 注册中心20000,、Turbine的20001、Dashboard的20002
spring:
application:
name: hystrix-dashboard
server:
port: 20002
4. HystrixDashboardApplication
@SpringCloudApplication
@EnableHystrixDashboard
package com.imooc;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@SpringCloudApplication
@EnableHystrixDashboard
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
4.要把Hystrix所有的端点暴露出来
是通过actuator来暴露的
依赖已经加到了foodie-cloud-web-components微服务中了,所以其他微服务都已经加载了这个依赖
所有微服务的web微服务基本上是加载了actuator的
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
5.微服务foodie-user-web把端点开放出来
开启所有actuator-endpoint
在application-dev.yml中添加配置
## 开启所有actuator-endpoint
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
#生产环境下不能配置 '*'
include: '*'
# include: health, info, xxxx
security:
enabled: false
6.添加Hystrix依赖及配置
1.完成1-5的配置步骤还,其实还并没有暴露Hystrix的端点
2.Hystrix可以使用在foodie-user-web当中,也可以使用在foodie-user-service当中
3.这里把hystrix配置到service中,步骤如下
- 添加下面的hystrix依赖到foodie-user-service 的pom中。同样的把下面的依赖及actuator-endpoint配置到别的微服务当中,如foodie-order-service的pom和application-dev.yml中
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
- 列表第二项