zoukankan      html  css  js  c++  java
  • 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

    成功出现熔断面板

     

      

  • 相关阅读:
    webstorm11.0下载地址和webstorm11.0破解程序patcher.exe下载使用方法说明 前端IDE工具的利器
    20151224今天发现到的两篇关于CSS架构、可复用可维护CSS和CSS学习提升能有改变思想观念意识的文章 分别是CSS架构目标和说说CSS学习中的瓶颈
    GOF提出的23种设计模式是哪些 设计模式有创建形、行为形、结构形三种类别 常用的Javascript中常用设计模式的其中17种 详解设计模式六大原则
    HTML过滤器,用于去除XSS漏洞隐患。
    springboot的快速集成多数据源的启动器
    Springboot根据url后缀返回json或者xml或者html
    Springboot打包成War包并使其可以部署到Tomcat中直接运行
    数据脱敏工具类(包含手机号,银行卡号,邮箱,中文名称等)
    MySQL函数find_in_set介绍
    防止同一IP多次请求攻击
  • 原文地址:https://www.cnblogs.com/syscn/p/9741016.html
Copyright © 2011-2022 走看看