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语言函数调用
    安家之由
    算法设计新思路
    AcceptsReturn
    silverlight 导出DataGrid 数据到Excel
    siliverlight双击事件
    如何:以编程方式调用按钮的 Click 事件 (Visual C#)
    左连接出错
    C# 根据当前时间获取,本周,本月,本季度等时间段
    验证用户登陆
  • 原文地址:https://www.cnblogs.com/yjmyzz/p/8093462.html
Copyright © 2011-2022 走看看