zoukankan      html  css  js  c++  java
  • hystrix项目实战

    闲话少说:

    总共分6步:

    (1)添加hystrix依赖以及监控的依赖

    <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-hystrix</artifactId>
                <version>1.4.4.RELEASE</version>
            </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
                <version>2.0.3.RELEASE</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-hystrix-dashboard -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
                <version>1.4.3.RELEASE</version>
            </dependency>
    

      2、添加注解:

    3、如果是springboot2.0的话需要添加hystrix.stream的访问路径:

    加载application中即可:

     @Bean
        public ServletRegistrationBean getServlet() {
            HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
            ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
            registrationBean.setLoadOnStartup(1);
            registrationBean.addUrlMappings("/hystrix.stream");
            registrationBean.setName("HystrixMetricsStreamServlet");
            return registrationBean;
        }
    

     4、在配置文件中 添加配置 属性

    hystrix:
      command:
        default:
          execution:
            isolation:
              thread:
                timeoutInMilliseconds: 10000(访问超时配置,默认是1000ms)
          execution:
            timeout:
              enabled: false
          circuitBreaker:
            requestVolumeThreshold: 1(断路器状态更改,默认是一个借口有20个请求失败,现在改为1个请求失败即开启断路器)
    

      5、添加@HystrixCommand

    直接在有服务调用的地方加上即可,fallback可以不加

    6、查看监控界面:需要先访问,然后看下有没有数据,然后进入监控

  • 相关阅读:
    $Poj2228$/洛谷$SP283 Naptime$ 环形$DP$
    $Poj1952 $洛谷$1687 Buy Low,Buy Lower$ 线性$DP+$方案计数
    $Poj3585 Accumulation Degree$ 树形$DP/$二次扫描与换根法
    洛谷$1541$ 乌龟棋 线性$DP$
    $Loj10157$ 皇宫看守 树形$DP$
    $loj10156/$洛谷$2016$ 战略游戏 树形$DP$
    $Loj10155$ 数字转换(求树的最长链) 树形$DP$
    洛谷$2015$二叉苹果树
    $CH5302$ 金字塔 区间$DP$/计数类$DP$
    [hiho1035] 自驾旅行III
  • 原文地址:https://www.cnblogs.com/fengli9998/p/9259084.html
Copyright © 2011-2022 走看看