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相关接口

  • https://apim.docs.wso2.com/en/3.0.0/develop/product-apis/devportal-apis/devportal-v1/devportal-v1/#/APIs/get_apis__apiId__subscription_policies

api详细

/api/am/devportal/apis/{apiId}

api订阅策略详细

/api/am/devportal/apis/{apiId}/subscription-policies

来源链接:https://www.cnblogs.com/lori/p/18924931

© 版权声明
THE END
支持一下吧
点赞11 分享
评论 抢沙发
头像
请文明发言!
提交
头像

昵称

取消
昵称表情代码快捷回复

    暂无评论内容