wso2 api 管理器 (3.2.0) 中每个用户(订阅)的 Rest api 中每个资源的请求率限制

问题描述 投票:0回答:1

在 wso2 api 管理器(3.2.0)中: 1.在publisher中定义一个rest api 2.你定义一个资源 3.客户订阅并发送请求以通过wso2生成的令牌来定义资源 所以我想要的是限制每个用户每个资源的请求率,例如对令牌的任何限制。 那么我该怎么做呢?

request wso2 token limit wso2-api-manager
1个回答
0
投票

要实现每用户限速,需要编写自定义限速策略。

  1. 转到管理门户,速率限制策略 -> 自定义策略并添加您想要的自定义策略。

以下是自定义速率限制策略的示例,为管理员用户定义每分钟 5 个请求的限制。

名称:自定义策略
描述:自定义策略示例
关键模板:userId:apiContext:$apiVersion

悉地查询:

FROM RequestStream
SELECT userId, ( userId == '[email protected]'  and apiContext == '/pizzashack/1.0.0' and apiVersion == '1.0.0') AS isEligible ,
str:concat('[email protected]',':','/pizzashack/1.0.0:1.0.0') as throttleKey
INSERT INTO EligibilityStream;
FROM EligibilityStream [isEligible==true] #throttler:timeBatch(1 min)
SELECT throttleKey, (count(throttleKey) >= 5) as isThrottled, expiryTimeStamp group by throttleKey
INSERT ALL EVENTS into ResultStream;

您可以参考文档[1]以进一步参考。

[1] https://apim.docs.wso2.com/en/3.2.0/learn/rate-limiting/advanced-topics/custom-throtdling/

© www.soinside.com 2019 - 2024. All rights reserved.