Our requirement is to extract customer id from API request, then use it as key to control call rate.
- If no customer id in the request, don’t control it. (Couldn’t find how to configure it in Azure.)
- If request contains customer id,
- Set different rate limit to some customer ids. (Couldn’t find how to configure in Azure. Particularly if two rate-limit-by-key policy, which one will take effect?)
- If not set rate limit in previous step, use a constant rate limit. (It supported by Azure as below policy)
For example, there are A, B, C, D customer ids, we want to set 20 calls/sec to A, set 30 calls/sec to B, and to others set 10 calls/sec as limit.
Any ideas or workaround on this concern?
Thanks!
<rate-limit-by-key
calls="100"
renewal-period="60"
counter-key="@(
string inBody = context.Request.Body.As<string>(preserveContent: true);
string pattern = @"<h:CustomerId (.*?)>(.*?)</h:CustomerId>";
Regex rgx = new Regex(pattern);
var match = rgx.Match(inBody);
if (match.Success)
{ return match.Groups[2].Value.Trim();
}
else
{return ""; })
"/>