zoukankan      html  css  js  c++  java
  • Hystrix超时测试

     1 package com.cookie.test;
     2 
     3 import com.netflix.hystrix.HystrixCommand;
     4 
     5 import com.netflix.hystrix.HystrixCommandGroupKey;
     6 
     7 import java.util.Random;
     8 
     9 /**
    10 
    11 * author : cxq
    12 
    13 * Date : 2019/6/28
    14 
    15 *
    16 
    17 * Hystrix超时测试
    18 
    19 */
    20 
    21 public class HystrixCommandTest extends HystrixCommand<String> {
    22 
    23   public String name ;
    24 
    25   public HystrixCommandTest( String name) {
    26 
    27   // 设置超时时间100ms
    28 
    29     super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"),100);
    30 
    31     this.name = name;
    32 
    33   }
    34 
    35   @Override
    36 
    37   protected String run() throws InterruptedException {
    38 
    39     int excution = new Random().nextInt(200);
    40 
    41     System.out.println(" 执行时间 :"+excution + "ms");
    42 
    43     Thread.sleep(excution);
    44 
    45     return "Hello "+name ;
    46 
    47   }
    48 
    49   @Override
    50 
    51   protected String getFallback() {
    52 
    53   return "error ! 降级处理 ";
    54 
    55   }
    56 
    57   public static void main(String[] args) {
    58 
    59     HystrixCommandTest test = new HystrixCommandTest("Ketty");
    60 
    61     System.out.println(test.execute());
    62 
    63   }
    64 
    65 }

    输出结果展示:

    1、 执行时间 :177ms

    error ! 降级处理

    2、执行时间 :5ms

    Hello Ketty

  • 相关阅读:
    Flink 架构和拓扑概览
    Flink 如何背压
    流式计算的时间模型
    流式计算的背压问题
    大数据流式计算容错方案演进之路
    Flink 任务提交
    Flink wordCount
    线性回归和逻辑回归的区别
    Nginx反向代理后配置404页面
    Httpclient 实现带参文件上传
  • 原文地址:https://www.cnblogs.com/pretttyboy/p/11325705.html
Copyright © 2011-2022 走看看