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

    }
    }
  • 相关阅读:
    MySQL 分区
    InnoDB 锁
    【神经网络】自编码聚类算法--DEC (Deep Embedded Clustering)
    【神经网络】变分自编码大杂烩
    【异常检测】Isolation forest 的spark 分布式实现
    【推荐系统】评估指标总结
    【推荐系统】neural_collaborative_filtering(源码解析)
    hadoop之计数器和管道的mrunit测试
    thrift0.5入门操作
    awk之close函数
  • 原文地址:https://www.cnblogs.com/tiancai/p/9578461.html
Copyright © 2011-2022 走看看