【发布时间】:2021-02-25 08:05:54
【问题描述】:
我使用 WSO2 API Managementt 2.6.0 作为我的 Spring Boot REST API 前面的 API 网关。
我想添加一个自定义限制策略来设置每个最终用户 ip 地址的速率限制,该地址由面向互联网的 WAF 放入请求标头 X-Forwarded-For。
WSO2 文档显示了一些用 Siddhi 语言编写的自定义策略示例,但没有足够的示例。
我能找到的最详细的文章是https://dzone.com/articles/implement-user-based-throttling-with-wso2-api-mana,它展示了一个userId限制速率的例子。
FROM RequestStream
SELECT userId, userId as throttleKey
INSERT INTO EligibilityStream;
FROM EligibilityStream#throttler:timeBatch(1 min)
SELECT throttleKey, (count(userId) >= 5) as isThrottled, expiryTimeStamp group by throttleKey
INSERT ALL EVENTS into ResultStream;
上述 Siddhi 查询告诉 WSO2 从请求中提取userId 并将其用作throttleKey 并限制每个throttleKey 每1 分钟少于5 个事务。
我想知道如何修改此 Siddhi 查询以使用请求标头中的 IP 地址 X-Forwarded-For 而不是 userId。
【问题讨论】:
标签: wso2 throttling api-gateway rate-limiting