Kong Gateway:一个 API 网关怎么处理每一次调用Kong Gateway: how an API gateway handles each call
Kong 是基于 Nginx 的开源 API 网关。应用调用 Kong,Kong 把每次调用转给对的后端。途中可以认出调用方、限流、记日志。
一次调用。 Kong 匹配一条路由,运行它的插件,挑一个后端,再把回复送回去。匹配不到路由就回 404。
插件干大部分活。自带 45 个:认证、限流、改写、日志和指标。
插件规则。 加载插件不等于开启。开启后,最具体的设置生效,优先级高的先跑。也可以自己写:用 Lua,或通过插件服务器用 Go、JavaScript。
选后端。 upstream 把调用分给多个目标,默认轮询。健康检查要自己开。调用失败会重试,默认最多 5 次。
配置经 Admin API、Kong Manager 或文件写入。存在 Postgres 里,或不用数据库,放在内存里(DB-less)。
混合模式(设置项 role)把活分开。控制面管数据库,把整份配置推给数据面,数据面处理流量。
AI 插件让 Kong 接在 LLM 前面。AI Proxy 用一种调用形状,翻译给 9 家提供方。token 日志默认关闭。
运行。 kong 命令负责准备、启动、重载和摘流一个节点。8007 端口的 Status API 报告健康状态和指标。
Kong is an open-source API gateway built on Nginx. Apps call Kong, and Kong passes each call on to the right backend. On the way it can check who is calling, limit traffic and log the call.
One call. Kong matches a route, runs the plugins for it, picks a backend and sends the answer back. No matching route means a 404.
Plugins do most of the work. 45 come bundled: auth, traffic limits, rewrites, logs and metrics.
Plugin rules. Loading a plugin doesn't turn it on. Turned on, the most specific setting wins, and higher priority runs first. You can write your own in Lua, or in Go or JavaScript through a plugin server.
Picking a backend. An upstream spreads calls over several targets. Round-robin is the default. Health checks are off until you set them. A failed call is retried, up to 5 times by default.
Config goes in through the Admin API, Kong Manager or a file. It lives in Postgres, or in memory with no database (DB-less).
Hybrid mode (a role setting) splits the work. A control plane holds the database and pushes the whole config to data planes, which serve the traffic.
AI plugins put Kong in front of LLMs. AI Proxy speaks one call shape and translates it for 9 providers. Token logging is off by default.
Running it. The kong command prepares, starts, reloads and drains a node. The Status API on port 8007 reports health and metrics.
来源Source: github.com