kong gateway 插件使用

简介: kong 插件使用, 其中限流插件是默认安装的

1.限流

​ 限流被用来控制网络请求的流量,能够被用来阻止DoS 攻击,限制网络抖动,和其他形式的过载,没有限流,会导致客户端无限制访问,导致服务不可用。

​ Kong Gateway imposes rate limits on clients through the use of the Rate Limiting plugin. When rate limiting is enabled, clients are restricted in the number of requests that can be made in a configurable period of time. The plugin supports identifying clients as consumers or by the client IP address of the requests.

2. 全局限流

  • 启动限流插件

    kong gateway默认安装了限流插件,通过如下指令启动插件

    curl -i -X POST http://localhost:8001/plugins \
      --data name=rate-limiting \
      --data config.minute=5 \
      --data config.policy=local
    

    启用成功返回如下:

    ...
    "id": "fc559a2d-ac80-4be8-8e43-cb705524be7f",
    "name": "rate-limiting",
    "enabled": true
    ...
    
  • 验证

​ 执行以下命令,发送六次请求,超过6次 你会收到http 返回码429 “API rate limit exceeded” error:

for _ in {1..6}; do curl -s -i localhost:8000/mock/request; echo; sleep 1; done
 
  • 服务级限流

    curl -X POST http://localhost:8001/services/example-service/plugins \
       --data "name=rate-limiting" \
       --data config.minute=5 \
       --data config.policy=local
  • 路由级限流

    curl -X POST http://localhost:8001/routes/example-route/plugins \
       --data "name=rate-limiting" \
       --data config.minute=5 \
       --data config.policy=local
    
  • 消费级限流

    • 创造一个消费者

      curl -X POST http://localhost:8001/consumers/ \
        --data username=jsmith
    • 启用消费级限流

      curl -X POST http://localhost:8001/plugins \
         --data "name=rate-limiting" \
         --data "consumer.username=jsmith" \
         --data "config.second=5"
      

深度限流

The Rate Limiting Advanced 是企业级的限流插件,提供更优秀的限流算法。

相关文章
|
监控 数据可视化 安全
探究架构之 - 45张图玩转Kong Gateway,建议收藏系列 (一)
探究架构之 - 45张图玩转Kong Gateway,建议收藏系列 (一)
765 1
探究架构之 - 45张图玩转Kong Gateway,建议收藏系列 (一)
kong gateway 授权插件配置
kong gateway 授权插件配置 auth
230 0
探究架构之 - 45张图玩转Kong Gateway,建议收藏系列 (三)
探究架构之 - 45张图玩转Kong Gateway,建议收藏系列 (三)
235 0
探究架构之 - 45张图玩转Kong Gateway,建议收藏系列 (三)
|
应用服务中间件 API 数据安全/隐私保护
探究架构之 - 45张图玩转Kong Gateway,建议收藏系列 (二)
探究架构之 - 45张图玩转Kong Gateway,建议收藏系列 (二)
238 0
探究架构之 - 45张图玩转Kong Gateway,建议收藏系列 (二)
|
前端开发 关系型数据库 应用服务中间件
API Gateway Kong在Rainbond上的部署
Kong是一个可扩展的开源API平台(也称为API网关,API中间件或微服务服务网格)。Kong最初是由Kong Inc(以前称为Mashape)实现的,用于为其API Marketplace维护、管理和扩展超过15,000个微服务,这些微服务每月产生数十亿个请求。
1974 0
|
6月前
|
JSON 应用服务中间件 nginx
如何修改kong网关access.log的日志格式
有需要需要调整kong网关的日志格式,调整日志输出内容,由于原来使用docker部署kong网关,并且使用了环境变量指定了网关运行的参数,这里在以下介绍的方式还需要修改容器的环境变量,但是也提供了一条思路,就是部署网关的时候,统一使用kong.conf进行配置
303 0
|
前端开发 NoSQL 关系型数据库
Kong网关介绍以及在Docker上部署容器以及Dashboard
Kong 是在客户端和(微)服务间转发API通信的API网关,通过插件扩展功能
1744 0
Kong网关介绍以及在Docker上部署容器以及Dashboard
|
9月前
|
Ubuntu API 数据库
kong网关插件开发初探
kong插件开发初探
253 0
|
API 微服务
kong 网关配置指引
kong 网关配置指引
772 0
kong 网关配置指引