zoukankan      html  css  js  c++  java
  • spring cloud:Edgware.RELEASE版本中zuul回退方法的变化

    Edgware.RELEASE以前的版本中,zuul网关中有一个ZuulFallbackProvider接口,代码如下:

    public interface ZuulFallbackProvider {
    
    	/**
    	 * The route this fallback will be used for.
    	 * @return The route the fallback will be used for.
    	 */
    	public String getRoute();
    
    	/**
    	 * Provides a fallback response.
    	 * @return The fallback response.
    	 */
    	public ClientHttpResponse fallbackResponse();
    }
    

    其中fallbackResponse()方法允许程序员在回退处理中重建输出对象,通常是输出“xxx服务不可用,请稍候重试”之类的提示,但是无法捕获到更详细的出错信息,排错很不方便。

    估计spring-cloud团队意识到了这个问题,在Edgware.RELEASE中将该接口标记为过时@Deprecated,同时在它下面派生出了一个新接口:

    public interface FallbackProvider extends ZuulFallbackProvider {
    
    	/**
    	 * Provides a fallback response based on the cause of the failed execution.
    	 *
    	 * @param cause cause of the main method failure
    	 * @return the fallback response
    	 */
    	ClientHttpResponse fallbackResponse(Throwable cause);
    }
    

    提供了一个新的重载版本,把异常信息也当作参数传进来了,这样就友好多了,在处理回退时可以输出更详细的信息。参考下面的代码:

    if (cause != null && cause.getCause() != null) {
            String reason = cause.getCause().getMessage();
            //输出详细的回退原因
            ...
    }
  • 相关阅读:
    VMware 11安装Mac OS X 10.10 (转载)
    ios]企业开发者账号申请
    SQL SERVER sa无法登陆的问题
    接触Ubuntu的第一周大致总结
    疯狂VirtualBox实战讲学录 以及 virtualbox完全学习手册 之我见
    必须使用角色管理工具 安装或配置microsoft.net framework 3.5
    02_brk/sbrk
    How to install qt5.9
    026_pickle
    024_iterator
  • 原文地址:https://www.cnblogs.com/yjmyzz/p/8093462.html
Copyright © 2011-2022 走看看