請求類型
Pigeon中請求的處理是採用一個責任鏈的模式,Netty服務器中將接受的請求序列化成Request對象,然後拋到Pigeon的責任鏈中處理。Pigeon將請求分爲四個類型(參見ProviderProcessHandlerFactory)
業務邏輯 bizInvocationHandler
心跳檢查 heartBeatInvocationHandler
健康檢查 healthCheckInvocationHandler
心跳掃描 scannerHeartBeatInvocationHandler
處理流程
每一個handler通過一個filter列表爲構建參數創建
重點關注這裏的bizInvocationHandler,這個實例就是業務邏輯處理的主體。那麼本文要講的限流是如何實現的呢?
就是在GatewayProcessFilter內部
methodAppLimitMap //GatewayProcessFilter內部存儲每個method對應的請求上線
ProviderStatisticsHolder : methodCapacityBuckets 存儲了每個method的請求量
當請求量大於限制時就會拋出異常
if (requests + 1 > limit) { throw new RejectedException(String.format("Max requests limit %s reached for request from app:%s", limit, fromApp)); }