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

    }
    }
  • 相关阅读:
    希尔伯特空间
    Java基础之类型转换总结篇
    超实用在线编译网站,编辑器
    3269: 万水千山粽是情
    Problem A: 李白打酒
    2370: 圆周率
    C语言fmod()函数:对浮点数取模(求余)
    C语言exp()函数:e的次幂函数(以e为底的x次方值)
    2543: 数字整除
    2542: 弟弟的作业
  • 原文地址:https://www.cnblogs.com/tiancai/p/9578461.html
Copyright © 2011-2022 走看看