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";

    }
    }
  • 相关阅读:
    VBS发送邮件-1
    docker命令
    NLP | 自然语言处理
    windows: Python安装scipy,scikit-image时提示"no lapack/blas resources found"的解决方法
    Sense2vec with spaCy and Gensim
    python 去停用词
    nohup command > myout.file 2>&1 &
    NLTK vs SKLearn vs Gensim vs TextBlob vs spaCy
    Gensim进阶教程:训练word2vec与doc2vec模型
    Gensim入门教程
  • 原文地址:https://www.cnblogs.com/tiancai/p/9578461.html
Copyright © 2011-2022 走看看