
正文
spring cloud (五) 熔断面板 聚合熔断 turbine
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
改造feign 项目
1 启动类添加注解 @EnableHystrix
2 添加如下配置文件
#ji
eureka.instance.metadata-map.cluster=MAIN
#actuator
management.server.port=9003
management.endpoints.web.exposure.include="*"
management.endpoints.web.cors.allowed-origins="*"
management.endpoints.web.cors.allowed-methods="*"
feign.hystrix.enabled=true
3 添加如下 pom依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<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>
创建一个springboot项目 spring-cloud-turbine
1 pom.xml
<?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">
<modelVersion>4.0.</modelVersion> <groupId>com.example</groupId>
<artifactId>Spring-Cloud-Turbine</artifactId>
<version>0.0.-SNAPSHOT</version>
<packaging>jar</packaging> <name>Spring-Cloud-Turbine</name>
<description>Demo project for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0..RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<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-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
2 配置文件
server.port=
spring.application.name=turbine eureka.client.service-url.defaultZone=http://127.0.0.1:8080/eureka/ turbine.app-config=feign-consumer
# dan ge setting
#turbine.cluster-name-expression=new String("default")
#turbine.combine-host-port=true #ji qun setting
turbine.aggregator.clusterConfig=MAIN
turbine.cluster-name-expression=metadata['cluster']
3 启动类
@SpringBootApplication
@EnableTurbine
@EnableHystrixDashboard
public class SpringCloudTurbineApplication { public static void main(String[] args) {
SpringApplication.run(SpringCloudTurbineApplication.class, args);
}
}
依次启动 eureka ,feign,turbine 三个项目
访问 http://127.0.0.1:7032/hystrix ,出现如下网页
输入 http://127.0.0.1:7032/turbine.stream?cluster=MAIN
成功出现熔断面板








