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

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

     

  • 相关阅读:
    ios中的任务分段
    UVA 531
    OGG同构(ORACLE-ORACLE)、异构(ORACLE-MYSQL)同步配置及错误解析
    JavaScript自调用匿名函数
    Redis 主从配置和参数详解
    python开发环境设置(windows)
    Havel-Hakimi定理 hdu2454 / poj1695 Havel-Hakimi定理
    libevent源码分析-介绍、安装、使用
    Linux网络监控工具nethogs
    spring(3)------控制反转(IOC)/依赖注入(DI)
  • 原文地址:https://www.cnblogs.com/draymond/p/12747738.html
Copyright © 2011-2022 走看看