简体   繁体   English

使用Azure API管理制作公共API

[英]Making a Public API using Azure API Management

I am using Azure API Management to manage my Web Apps in Azure. 我正在使用Azure API管理在Azure中管理我的Web应用程序。
However, I want to make some of my APIs public, and do not want the user to subscribe to those. 但是,我想将某些API公开,并且不希望用户订阅这些API。
The unsubscribed users must only be able to make 10 calls per minute. 取消订阅的用户每分钟只能拨打10个电话。
I created a new subscription without any key and added the rate-limit policy (10 calls per minute) to it, however, when I make 10 calls in 10 seconds, I get 429 status code, which is pretty much understood. 我创建了一个没有任何密钥的新订阅,并在其中添加了速率限制策略(每分钟10次呼叫),但是,当我在10秒内拨打10次呼叫时,我得到429状态代码,这是非常容易理解的。
But within the same time duration (one minute), if I make calls to the same API, from different device, I still get the 429 status code. 但是在同一时间段(一分钟)内,如果我从其他设备调用相同的API,我仍然会得到429状态代码。
From the second device, the user must be able to access the API, since, it has not accessed the API at all. 用户必须能够从第二个设备访问API,因为它根本没有访问API。
How can this be achieved in the Azure API Management.? 如何在Azure API管理中实现这一点?

By reading the following document, I have found the solution. 通过阅读以下文档,我找到了解决方案。

https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/api-management/api-management-sample-flexible-throttling.md https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/api-management/api-management-sample-flexible-throttling.md

<rate-limit-by-key  calls="10"
          renewal-period="60"
          counter-key="@(context.Request.IpAddress)" />

<quota-by-key calls="1000000"
          bandwidth="10000"
          renewal-period="2629800"
          counter-key="@(context.Request.IpAddress)" />

However, there is a strange thing happening with it. 但是,发生了一件奇怪的事情。
I have set the renewal-period="60" in the API Management. 我已经在API管理中设置了renewal-period="60"
When I make the requests (10 requests in approx. 10 secs) using the first device (connected via wifi), I get 429 status code and the message as "message": "Rate limit is exceeded. Try again in 34 seconds." 当我使用第一个设备(通过wifi连接)发出请求(大约10秒钟内有10个请求)时,我得到429状态代码,并显示"message": "Rate limit is exceeded. Try again in 34 seconds."

However, when I make the requests (10 requests in approx. 10 secs) using the second device (mobile phone connected via cellular network), I should be getting a message indicating that retry in 50 or 60 seconds. 但是,当我使用第二个设备(通过蜂窝网络连接的移动电话)发出请求(大约10秒钟内有10个请求)时,我应该收到一条消息,指示在50或60秒内重试。
What I get on the second device is the the following: 我在第二台设备上得到的是以下内容:
"message": "Rate limit is exceeded. Try again in 24 seconds."
Which is sort of strange, since the time indicates the renewal time for the first device. 有点奇怪,因为时间表示第一台设备的更新时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM