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

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

     

  • 相关阅读:
    创建nodejs服务器
    研磨设计模式学习笔记2外观模式Facade
    研磨设计模式学习笔记4单例模式Signleton
    研磨设计模式学习笔记1简单工厂(SimpleFactory)
    getResourceAsStream小结
    研磨设计模式学习笔记3适配器模式Adapter
    oracle数据库代码块
    DecimalFormat
    .NET中常用的代码(转载)
    WebClient的研究笔记
  • 原文地址:https://www.cnblogs.com/draymond/p/12747738.html
Copyright © 2011-2022 走看看