zoukankan      html  css  js  c++  java
  • springcloud(10)-断路器监控

    1.创建hystrix-dashboard子项目

    2.添加pom.xml包

    <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>
      <parent>
        <groupId>com.zhangdemo</groupId>
        <artifactId>springcloud</artifactId>
        <version>0.0.1-SNAPSHOT</version>
      </parent>
      <artifactId>productServiceHystrixDashboard</artifactId>
    
      <dependencies>
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-actuator</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>
    
      </dependencies>
    
    </project>
    

    3.ProductServiceHystrixDashboardApplication

    @SpringBootApplication
    @EnableHystrixDashboard
    public class ProductServiceHystrixDashboardApplication {
        public static void main(String[] args) {
            int port = 8020;
            if(!NetUtil.isUsableLocalPort(port)) {
                System.err.printf("端口%d被占用了,无法启动%n", port );
                System.exit(1);
            }
            new SpringApplicationBuilder(ProductServiceHystrixDashboardApplication.class).properties("server.port=" + port).run(args);
    
        }
    
    }
    

    4.配置文件修改:

    spring:
      application:
        name: hystrix-dashboard
    

    5.ProductViewServiceFeignApplication增加 @EnableCircuitBreaker注解

    6.AccessViewService类进行访问:

    public class AccessViewService {
    
        public static void main(String[] args) {
    
            while(true) {
                ThreadUtil.sleep(1000);
                try {
                    String html= HttpUtil.get("http://127.0.0.1:8012/products");
                    System.out.println("html length:" + html.length());
                }
                catch(Exception e) {
                    System.err.println(e.getMessage());
                }
    
            }
    
        }
    }
    

    7.测试

    (1打开http://localhost:8020/hystrix

    (2输入: http://localhost:8012/actuator/hystrix.stream

    image-20201116145627617

    (3点击[Monitor Stream]

    (4看到如下页面

    image-20201116145027777
  • 相关阅读:
    修改spring源码重写classloader实现项目加密
    Java验证工具类
    jsp相关基础知识
    HTTP协议详细分析
    Java获取Linux和Window系统CPU、内存和磁盘总使用率的情况
    关于Genymotion下载比较慢的解决办法
    Android Studio:Failed to resolve ***
    ActionBar设置自定义setCustomView()留有空白的问题
    Service是什么?Service又不是什么?
    Socket--Android王国的外交发言人
  • 原文地址:https://www.cnblogs.com/NaoDaiYouDianDa/p/13985429.html
Copyright © 2011-2022 走看看