help request: How to Customize Load Balancing for TCP Requests #8317
Unanswered
haydn-yang
asked this question in
Q&A
Replies: 1 comment
-
try to hook |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I now need to do custom load balancing of content based on TCP requests, I tried to implement it in the balance phase of the plugin, but it never worked.
Plugin core code
`
local balancer = require("ngx.balancer")
local plugin_name = "xm-plugin"
……
function _M.balancer(conf, ctx)
core.log.warm("balance-log: IP: ", ctx.balancer_ip, ", Port: ", ctx.balancer_port)
-- Fake data, the host will actually be obtained through the interface
local host = {"127.0.0.1:10000", "127.0.0.1:20000"}
end
……
`
Add route
`
curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"plugins": {
"xm-plugin":{
}
},
"upstream": {
"scheme": "tcp",
"nodes": {
},
"type": "roundrobin"
},
"server_port": 8000
}'
`
Environment
All components are started via docker on mac (m1)
apisix version
): 3.0.0-debianuname -a
): Darwin Kernel Version 21.6.0openresty -V
ornginx -V
):1.19.10-alpinecurl http://127.0.0.1:9090/v1/server_info
): v3.4.15-arm64luarocks --version
):Beta Was this translation helpful? Give feedback.
All reactions