【发布时间】:2018-01-02 21:06:48
【问题描述】:
我想像这样限制我的产品:
- starter:没有并行调用(只允许同步调用)
- 高级版:10 个并行调用(允许有限制的异步调用)
api网关后面的服务需要一些时间,所以有些人想进行异步调用以获得更多结果。
我从 azure 发现的唯一限制是速率和配额限制。但是它们的限制是每次调用,我需要它来进行并行调用。
我想过这个逻辑:
<inbound>
<http-call>
send user id to a azure function, that increases the counter for the user, returns the current counter
</http-call>
<when>
compare counter value with the product limit (x = 0 for starter or x <= 10 for premium)
if true route to the service, if false generate a "too many requests" response
</when>
</inbound>
<outbound>
<http-call>
decrease the counter
</http-call>
</outbound>
我不确定这是否是最好的逻辑,因为函数需要时间来更新值。有没有办法保存某种“共享变量”,每个请求都可以访问它以检查 api 管理中的计数器,而不是通过外部函数?
【问题讨论】:
-
目前唯一的方法是外部服务(如您的示例)或缓存(如下面的 mimo)。很快将引入新策略以允许限制并发,但仅限于每个节点,即不针对整个服务全局。
标签: azure parallel-processing rate-limiting azure-api-management