I found a random interface from the Internet
Weather interface:http://t.weather.sojson.com/api/weather/city/101020100
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:
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)
|