如何使用Kong Api-Gateway进行有条件的请求终止?
我正在使用Kong Api-Gateway进行API管理。
假设我有一个名为Alpha的服务。我在端口80和端口8000上的alpha在名为kong-net
的同一docker网络中提供服务,每个都在另一个docker容器上,一个名为kong
和另一个。命名alpha
我正在使用声明db的模式使用kong。因此,我的配置应如下kong.yml
:
_format_version: "2.1"
_transform: true
services:
- name: alpha-live
host: alpha
port: 8000
protocol: http
path: /live
routes:
- name: alpha-live
methods:
- GET
paths:
- /alpha/live
strip_path: true
我要寻找的是,当http:// http:// kong/alpha/live/live
决定
时终止
- 请求 或
- 。
通过某些条件(可能来自SLA指标来自SLA指标)设置在请求内容上的某些情况(可能来自SLA指标) 它可能是标头,车身等的关键,价值等
我有一种方法吗?
有此插件request-termination
https://docs.konghq.com/hub/kong/kong-inc-inc/request-termination/ 但不能使用条件。
有任何想法吗?
I am using kong API-gateway for API management.
Suppose I have a service named alpha. I am serving kong on port 80 and alpha on port 8000 both in the same docker network named kong-net
and each on a different docker container, one named kong
and the other named alpha
I am using kong in a declarative DB-less mode. So my configuration should be as below in kong.yml
:
_format_version: "2.1"
_transform: true
services:
- name: alpha-live
host: alpha
port: 8000
protocol: http
path: /live
routes:
- name: alpha-live
methods:
- GET
paths:
- /alpha/live
strip_path: true
What I am looking for is that when a request is received by http://kong/alpha/live
decide to either
- terminate the request
OR - pass it
http://alpha:8000/live
based on some conditions (probably coming from SLA metrics) set on the content of the request. it might be a key, value in the header, body, etc
I there a way to do it?
There is this plugin request-termination
https://docs.konghq.com/hub/kong-inc/request-termination/ but cannot use conditions.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用请求终止插件,因为它可以通过可以成为标头的触发器来处理,请查看 https://docs.konghq.com/hub/kong/kong-inc/request-termination/#new-inew-inw-inw-inw-210 。一个例子看起来像这样。
You can use the request-termination plugin because it able to be handled by trigger which can be part of the header, have a look at https://docs.konghq.com/hub/kong-inc/request-termination/#new-in-210. An example could look like this;
您始终可以用Kong支持编写自定义插件的任何语言编写自己的插件。截至目前,支持Lua(DUH),Golang,JS和Python得到了支持,并通过其各自的插件开发套件(PDK)启用了开发( https://docs.konghq.com/gateway/gateway/latest/reference/external-plugins/ )
还可以帮助您在请求生命周期的各个阶段(或Kong称为kong称之为阶段)运行插件,如果您熟悉,则可以在官方DOC
中实现不同的方法,如果您熟悉有了Golang,我建议您继续前进,因为它的代码非常简单。我已经在自己的用例中写了一篇,以终止上一个前5s之前的任何请求。您可以编写逻辑以在任何需要的条件下完成相同的操作。
尽管部署这可能是一个挑战(因为由于某种原因,即使PDK以其他语言存在,该文档非常局限于在LUA中的脚本),即使我也遇到了同样的尝试,试图通过Helm在Kubernetes群集上部署一个文档,但是,如果您正在与Docker合作,Dockerfile和下面链接问题中提供的链接就足够了。
希望这会有所帮助!!
kong自定义GOLANG插件>
You can always write your own plugin in any of the languages that kong supports for writing custom plugins. As of now lua (duh), golang, js and python are supported and development is enabled via their own respective plugin development kits (PDKs) released by kong (https://docs.konghq.com/gateway/latest/reference/external-plugins/)
Also to help you accomplish running your plugins at various stages (or phases as kong calls it) of the request lifecycle, there are different methods you can implement which are very well documented in the official doc
If you are familiar with golang, I'd suggest you go ahead with that as it's fairly straight forward with very minimal code. I've written one in my own use case for terminating any requests that arrive before 5s of the previous one. You can write your logic to accomplish the same with any condition you require.
Although deploying it might be a challenge (because for some reason even though the pdks exist in other languages, the documentation is very much limited to scripting in lua), even I was stuck with the same trying to deploy one on a kubernetes cluster via helm, but if you're working with docker, the dockerfile and the links provided in the question of the link below would be enough for you.
Hope this helps !!
Kong custom golang plugin not working in kubernetes/helm setup