This article is a mirror article of machine translation, please click here to jump to the original article.

View: 8983|Reply: 0

Use the kong rate-limiting plug-in to control the request rate of the interface

[Copy link]
Posted on 11/21/2018 4:21:48 PM | | | |
I found a random interface from the Internet

Weather interface:http://t.weather.sojson.com/api/weather/city/101020100
Docker deployment kong-dashboard tutorial
https://www.itsvse.com/thread-5684-1-1.html
(Source: Architect_Programmer)


Use "kong-dashboard" to create a service, the main configuration is as follows, and the other configurations are just as follows.



Of course, you can also create a service through the kong api, the documentation link:https://docs.konghq.com/0.14.x/admin-api/#service-object

To create a route using "kong-dashboard", you can't create it directly on the routing interface, you need to click the first button on the right side of each line from the service list to create it, the main configuration is as follows:



Of course, routes can also be created via the kong api, with a link to the documentation:https://docs.konghq.com/0.14.x/admin-api/#route-object


We access the kong api gateway at http://ip:8000/weather/{city code}, as shown below, which returns the weather conditions in Shanghai and Jining, respectively,



Added the rate control "rate-limiting" plugin

Plugin Introduction:https://docs.konghq.com/hub/kong-inc/rate-limiting/

The number of HTTP requests a developer can make per second/minute/hour. There must be at least one limitation.

The main configuration is as follows, only the same IP can be accessed up to 30 times per minute:



We use ab mock requests, tutorials:

windows Apache ab web site stress test
https://www.itsvse.com/thread-4836-1-1.html
(Source: Architect_Programmer)
A total of 120 requests were made, and the number of concurrency was 10, and the return result was as follows:



Requested in total120Failed90time, it took a total of 6.618 seconds, indicating that my rate limit is effective!

If the set access rate is exceeded, it will appear“429 Too Many Requests”status code and returns an error like this:

{"message":"API rate limit exceeded"}
(End)




Previous:Docker deployment kong-dashboard tutorial
Next:Yongle Dadian and Thirteen Classics Commentary
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com