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();
            //输出详细的回退原因
            ...
    }
  • 相关阅读:
    【C语言疯狂讲义】(三)C语言运算符
    RAII手法封装相互排斥锁
    《Java并发编程实战》第十一章 性能与可伸缩性 读书笔记
    Nginx之红黑树
    我第一家互联网公司产品开发周期
    javascript中的XML
    哈夫曼树
    【HttpClient4.5中文教程】【第一章 :基础】1.1运行请求(二)
    H3C开启Ssh
    H3C创建本地用户
  • 原文地址:https://www.cnblogs.com/yjmyzz/p/8093462.html
Copyright © 2011-2022 走看看