zoukankan      html  css  js  c++  java
  • Hystrix 服务降级一(服务端降级)

    pom

            <!-- hystrix-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            </dependency>

    1:单个方法降级

        @HystrixCommand(fallbackMethod = "paymenInfo_TimeOutHandler", commandProperties = {
                @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3000")
        })
        //  @HystrixCommand //没有特别指明,则用统一配置
        public String paymentInfo_TimeOut() {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "线程池:  " + Thread.currentThread().getName() + " paymentInfo_TimeOut";
        }

     降级的方法

        /**
         * 单个服务降级
         *
         * @return
         */
        public String paymenInfo_TimeOutHandler() {
            return "线程池:  " + Thread.currentThread().getName() + " paymenInfo_TimeOutHandler";
        }

    2:全局服务降级

    @Service
    @DefaultProperties(defaultFallback = "paymenInfo_GloableHandler")
    public class PaymentService {
        @HystrixCommand //没有特别指明,则用统一配置
        public String paymentInfo_TimeOut() {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "线程池:  " + Thread.currentThread().getName() + " paymentInfo_TimeOut";
        }

      降级的方法

        /**
         * 全局服务降级
         *
         * @return
         */
        public String paymenInfo_GloableHandler() {
            return "线程池:  " + Thread.currentThread().getName() + " paymenInfo_GloableHandler";
        }

     备注:服务降级一般用在客户端

     

  • 相关阅读:
    通用页面调用APP 互通
    HTML5[5]:在移动端禁用长按选中文本功能
    JAVA 中的基础
    手机访问PC网站自动跳转到手机网站代码
    自适应的设置字体的方式
    localStorage 与 sessionStorage
    《高级程序设计》3 基本慨念
    javascript基础
    jQuery技巧
    jQuery性能优化
  • 原文地址:https://www.cnblogs.com/draymond/p/12747738.html
Copyright © 2011-2022 走看看