码迷,mamicode.com
首页 > 编程语言 > 详细

spring cloud (五) 熔断面板 聚合熔断 turbine

时间:2018-10-04 10:12:49      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:conf   class   .repo   schema   ack   enc   let   one   ring   

  改造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

标签:conf   class   .repo   schema   ack   enc   let   one   ring   

原文地址:https://www.cnblogs.com/syscn/p/9741016.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!