欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Springcloud中Zuul的RibbonRoutingFilter有什么作用

本篇內容介紹了“Springcloud中Zuul的RibbonRoutingFilter有什么作用”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

創(chuàng)新互聯(lián)成都企業(yè)網站建設服務,提供網站建設、成都做網站網站開發(fā),網站定制,建網站,網站搭建,網站設計,響應式網站,網頁設計師打造企業(yè)風格網站,提供周到的售前咨詢和貼心的售后服務。歡迎咨詢做網站需要多少錢:13518219792

    spring-cloud-netflix-zuul的版本是2.1.2.release.

    圖1是RibbonRoutingFilter的繼承圖

            Springcloud中Zuul的RibbonRoutingFilter有什么作用

          圖1 類繼承圖

    RibbonRoutingFilter是個roue類型的ZuulFilter,如下List-1所示,它的filterOrder是10; 在run方法中首先構造commandContext,之后調用內部方法forward。

    List-1

@Override
public String filterType() {
    return ROUTE_TYPE;
}

@Override
public int filterOrder() {
    return RIBBON_ROUTING_FILTER_ORDER;
}

@Override
public boolean shouldFilter() {
    RequestContext ctx = RequestContext.getCurrentContext();
    return (ctx.getRouteHost() == null && ctx.get(SERVICE_ID_KEY) != null
            && ctx.sendZuulResponse());
}

@Override
public Object run() {
    RequestContext context = RequestContext.getCurrentContext();
    this.helper.addIgnoredHeaders();
    try {
        RibbonCommandContext commandContext = buildCommandContext(context);
        ClientHttpResponse response = forward(commandContext);
        setResponse(response);
        return response;
    }
    catch (ZuulException ex) {
        throw new ZuulRuntimeException(ex);
    }
    catch (Exception ex) {
        throw new ZuulRuntimeException(ex);
    }
}

    如下List-2所示,首先用ribbonCommandFactory構建RibbonCommand,之后調用RibbonCommand的execute(),這里的RibbonCommandFactory和RibbonCommand都是接口,具體實現有三個。

    List-2

protected ClientHttpResponse forward(RibbonCommandContext context) throws Exception {
    Map<String, Object> info = this.helper.debug(context.getMethod(),
            context.getUri(), context.getHeaders(), context.getParams(),
            context.getRequestEntity());

    RibbonCommand command = this.ribbonCommandFactory.create(context);
    try {
        ClientHttpResponse response = command.execute();
        this.helper.appendDebug(info, response.getRawStatusCode(),
                response.getHeaders());
        return response;
    }
    catch (HystrixRuntimeException ex) {
        return handleException(info, ex);
    }
}

    List-3 RibbonCommandFactory和RibbonCommand接口

public interface RibbonCommand extends HystrixExecutable<ClientHttpResponse> {

}

public interface RibbonCommandFactory<T extends RibbonCommand> {

	T create(RibbonCommandContext context);

}

    RibbonCommandFactory的三個實現類如下圖2

Springcloud中Zuul的RibbonRoutingFilter有什么作用

                                                                                          圖2

   HttpClientRibbonCommandFactory用于構建HttpClientRibbonCommand, OkHttpRibbonCommandFactory用于構建OkHttpRibbonCommand, RestClientRibbonCommandFactory用于構建RestClientRibbonCommand。

“Springcloud中Zuul的RibbonRoutingFilter有什么作用”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注創(chuàng)新互聯(lián)網站,小編將為大家輸出更多高質量的實用文章!

文章標題:Springcloud中Zuul的RibbonRoutingFilter有什么作用
文章URL:http://www.chinadenli.net/article4/ighhoe.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)手機網站建設App設計響應式網站品牌網站設計云服務器

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)