zuul 1.3.0 學習筆記
概述
- 提供servlet/filter/listener級别的請求過濾、請求路由、請求響應支援
- 參考
- http://blog.didispace.com/spring-cloud-source-zuul/
- http://www.scienjus.com/api-gateway-and-netflix-zuul/
- http://zhxing.iteye.com/blog/399668
IZuulFilter—->zuul過濾器
- IZuulFilter決定是否運作過濾器以及過濾器運作機制支援
- ZuulFilter提供子類覆寫過濾器類型/順序/執行過濾器方式機制
- pre
- PreDecoration—->ZuulFilter—->IZuulFilter(PreDecoration提供頭資訊支援)
- DebugRequest—->ZuulFilter—->IZuulFilter(DebugRequest調試資訊支援)
- route
- ZuulHostRequest—->ZuulFilter—->IZuulFilter(ZuulHostRequest依靠httpclient封裝成HostCommand,完成請求的執行)
- post
- SendResponseFilter—->ZuulFilter—->IZuulFilter(SendResponseFilter添加響應頭,回寫響應輸出流)
- error
- ErrorResponse—->ZuulFilter—->IZuulFilter(ErrorResponse寫入相應的異常資訊到responseBody)
ZuulRunner/FilterProcessor—->zuul運作器
- ZuulRunner負責初始化request/response到RequestContext,提供pre/post/route/error過濾器運作支援
- FilterProcessor過濾器執行的支援類,ZuulRunner委托相應執行方法給此
ZuulServlet/ZuulServletFilter—->啟動器
- ZuulServlet提供servlet級别的過濾器執行順序支援,正常pre-route-post,異常pre-error-post
- ZuulServletFilter提供filter級别的過濾器執行順序支援,正常pre-route-post,異常pre-error-post
其他支援
- RequestContext—->請求上下文支援,利用線程ThreadLocal建立key-value值對
- FilterLoader—->過濾器加載器,以key-list方式存放已有的過濾器
- FilterFileManager—->提供擷取過濾器支援
測試
- com.netflix.zuul.StartServer