Hystrix: Dashboard流监控

接上两张服务熔断

开始搭建Dashboard流监控

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">
    <parent>
        <artifactId>springcloud</artifactId>
        <groupId>com.kuang</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>springcloud-consumer-hystrix-dashboard</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <!--  消费者:实体类+web  不需要连接数据库,跟前端打交道的  -->
    <dependencies>
        <!--   Hystrix依赖   -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>

        <!--   Hystrix依赖   -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>


        <!-- Ribbon 集成      -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-ribbon</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>

        <!--    Eureka    -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>com.kuang</groupId>
            <artifactId>springcloud-api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!--    web 支持    -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--     热部署   -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

    </dependencies>

</project>
复制代码
<!--   Hystrix依赖   -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix</artifactId>
    <version>1.4.6.RELEASE</version>
</dependency>

<!--   Hystrix依赖   -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
    <version>1.4.6.RELEASE</version>
</dependency>

主启动类

java 复制代码
package com.kuang.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@SpringBootApplication
@EnableHystrixDashboard//开启
public class DeptConsumerDashboard_9001 {
    public static void main(String[] args) {
        SpringApplication.run(DeptConsumerDashboard_9001.class,args);
    }
}

启动

访问http://localhost:9001/hystrix

启动集群7001

在8001提供者里加个依赖

复制代码
<!--   Hystrix依赖   -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix</artifactId>
    <version>1.4.6.RELEASE</version>
</dependency>

在熔断里用这个监控才有效

主启动类里加一个bean放入IOC容器里

java 复制代码
package com.kuang.springcloud;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableEurekaClient //在服务启动后自动注册到 eureka服务端
@EnableDiscoveryClient//服务发现~
@EnableCircuitBreaker//添加对熔断的支持  ,开启断路器
public class DeptApplicationProviderHystrix_8001 {
    public static void main(String[] args) {
        SpringApplication.run(DeptApplicationProviderHystrix_8001.class,args);
    }


    //增加一个Servlet,配合我们的监控使用
    @Bean
    public ServletRegistrationBean hystrixMetricsStreamServlet(){
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        registrationBean.addUrlMappings("/actuator/hystrix.stream");//添加映射路径
        return registrationBean;
    }

}

服务熔断机制

相关推荐
wei_shuo16 天前
Spring Cloud OpenFeign:基于Ribbon和Hystrix的声明式服务调用
spring cloud·hystrix·ribbon
漫无目的行走的月亮1 个月前
微服务容错处理Hystrix
spring cloud·hystrix·微服务
编程、小哥哥1 个月前
springcloud之应用服务快速失败熔断降级保护 Hystrix
spring·spring cloud·hystrix
天下蒂一厨2 个月前
hystrix微服务部署
hystrix·微服务·架构
笑洋仟2 个月前
SpringCloud 配置 feign.hystrix.enabled: true 不生效
java·spring cloud·hystrix
别挡2 个月前
熔断降级 请求合并 请求缓存 线程池隔离 信号量隔离 openfeign整合Hystrix
java·hystrix·缓存
Lill_bin2 个月前
SpringCloud解读
分布式·后端·spring·spring cloud·hystrix·架构
是枫似风3 个月前
Hystrix——服务容错保护库
java·开发语言·spring boot·spring cloud·hystrix·云原生·eureka
vx2_Biye_Design4 个月前
Springcloud物流配送后台-计算机毕业设计源码69809
java·css·spring cloud·hystrix·eureka·ribbon·eclipse
卡卡angel4 个月前
Hystrix 线程池策略时使用ThreadLocal
hystrix