wso2~api訂閱策略與訂閱凍結
相關參考:
- https://jaadds.medium.com/monetizing-apis-with-wso2-api-manager-7af0438230d
- https://apim.docs.wso2.com/en/4.4.0/design/api-monetization/monetizing-an-api/#a-configure-the-billing-engine
- https://apim.docs.wso2.com/en/4.4.0/design/api-monetization/monetizing-an-api/#step-1-create-a-subscription-policy
- https://athiththan11.medium.com/subscribe-apis-using-store-rest-apis-54e94cd6c2ea
- https://www.postman.com/research-administrator-62482734/apim/documentation/l36zy25/wso2-api-manager-4-3-0-admin-rest-api?entity=folder-32294946-87737615-461c-4372-990b-af703de7e679
- https://blog.dtk2globle.com/implementing-request-throttling-with-wso2-api-manager
- https://cudakara.medium.com/rate-limiting-practices-in-wso2-api-manager-part-1-50c5f17b5f1e
api訂閱策略在admin后臺,你可以通過Rate Limiting Policies>Subscription Policies來添加和修改自定義的策略,并且它可以在使用次數(count),使用帶寬( Bandwidth),異常事件數量等方面對請求進行限制。
基本配置
限制單位
- Minute(s)
- Hour(s)
- Day(s)
- Month(s)
- Year(s)
請求數

請求帶寬

事件數

突發流量限制

免費與商業配置
免費與商業的策略,默認使用免費策略,商業策略可以自定義限制方式,它們在達到限制后都會對接口停止訂閱,直到下一個策略周期的到來


被限流后,將返回這個錯誤
# http 429
{
"code": "900804",
"message": "Message throttled out",
"description": "You have exceeded your quota .You can access API after 2025-Jun-10 09:40:00+0000 UTC",
"nextAccessTime": "2025-Jun-10 09:40:00+0000 UTC"
}
api訂閱的鎖定
開發者平臺,在應用中看到api的鎖定狀態

發布者對api管理員,可以鎖定某個api,可能對發布者管理員來說,某個應用使用不太正常,需要禁用它對api的訪問

應用訂閱的api被鎖定后,應用再調用api時,返回這個錯誤
# http 401
{
"code": "900907",
"message": "The requested API is temporarily blocked",
"description": "Access failure for API: /user-register/1.0.0, version: 1.0.0 status: (900907) - The requested API is temporarily blocked"
}
鎖定api的接口
/api/am/publisher/v4/subscriptions/block-subscription?subscriptionId=e55f1158-e291-4de4-a6e4-c500b902d025&blockState=BLOCKED
api訂閱狀態修改后生效的緩存時間
- 從文檔上看,緩存是15分鐘,如果你把api里的應用訂閱改成blocking,15分鐘后應用將不能訪問當前api
- https://apim.docs.wso2.com/en/latest/manage-apis/design/advanced-topics/block-subscription-to-an-api/

關閉緩存,配置實時生效
如果您不接受緩存的時長,或者需要實時讓配置生效,那可以把緩存關閉
- values.yaml(deployment.toml)
wso2:
apim:
configurations:
cache:
gateway_token:
# -- Gateway token cache enabled
enabled: false
# -- Gateway token cache expiration time
expiryTime: "15m"
resource:
# -- Gateway resource cache enabled
enabled: false
# -- Gateway resource cache expiration time
expiryTime: "900s"
km_token:
# -- Gateway KM token cache enabled
enabled: false
# -- Gateway KM token cache expiration time
expiryTime: "15m"
api策略中的商業計劃
這塊內容需要結合analytics功能來實現,并且需要配置monetization對應的銀行賬戶,以便生產費用后,如何將錢打到賬戶中
api相關接口
api詳細
/api/am/devportal/apis/{apiId}
api訂閱策略詳細
/api/am/devportal/apis/{apiId}/subscription-policies
浙公網安備 33010602011771號