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

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

     

  • 相关阅读:
    python生成试题库和界面 (python generate test database and layout)
    python生成数据库(python generate database)
    Go语言基础之流程控制
    Go语言基础之运算符
    Go语言基础之变量和常量
    VS Code配置Go语言开发环境
    Linux安装教程|详细
    安装Go语言及搭建Go语言开发环境
    Go语言
    Django2.0路由匹配path的用法
  • 原文地址:https://www.cnblogs.com/draymond/p/12747738.html
Copyright © 2011-2022 走看看