zoukankan      html  css  js  c++  java
  • Hystrix的用法

    package com.example.demo;
    
    import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
    import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping("/app")
    public class AppController {
    
        @RequestMapping("/get/{id}")
        @HystrixCommand(fallbackMethod = "getFallBack",  commandProperties = {
                @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500")
        })
        public  String get(@PathVariable("id") long id) throws  Exception  {
    
         // throw   new Exception("error");
     Thread.sleep(id);
            return  "get";
        }
    
        public String getFallBack(@PathVariable("id") long id) {
            return "getFallBack";
    
        }
    }
    package com.example.demo;

    import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
    import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;

    @RestController
    @RequestMapping("/app")
    public class AppController {

    @RequestMapping("/get/{id}")
    @HystrixCommand(fallbackMethod = "getFallBack", commandProperties = {
    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500")
    })
    public String get(@PathVariable("id") long id) throws Exception {

    // throw new Exception("error");
    Thread.sleep(id);
    return "get";
    }

    public String getFallBack(@PathVariable("id") long id) {
    return "getFallBack";

    }
    }
  • 相关阅读:
    UVA 562 Dividing coins
    who is in front of me 解题报告
    UVA 111 历史考试
    UVA 1045 最长公共子序列
    HDU 1003 解题报告
    ACM2014-04训练计划
    基于邻接表的新顶点的增加
    4004.六度空间理论
    4003.基于Dijsktra算法的最短路径求解
    4002.基于快排思想的查找
  • 原文地址:https://www.cnblogs.com/tiancai/p/9578461.html
Copyright © 2011-2022 走看看