spring cloud 熔断面板 聚合熔断 turbine

Posted 冬天不眠

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>Spring-Cloud-Turbine</artifactId>
    <version>0.0.1-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.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</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=7032
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

成功出现熔断面板

 

 

 

 

 

 

  

以上是关于spring cloud 熔断面板 聚合熔断 turbine的主要内容,如果未能解决你的问题,请参考以下文章

spring cloud微服务快速教程之 Spring Cloud Alibaba--sentinel-限流熔断降级

Spring Cloud - 熔断

Spring Cloud Zuul Filter 和熔断

spring cloud 学习 - hystrix 服务熔断处理

网关中加入熔断机制(Hystrix)

利用Spring Cloud实现微服务- 熔断机制