YangBin-365 opened a new issue, #8315:
URL: https://github.com/apache/apisix/issues/8315
### 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"}
local backend = host[1]
local ok, err = balancer.set_current_peer(backend, ngx.var.server_port)
if not ok then
-- ngx.log(ngx.ERR, "failed to set the current peer: ", err)
return 500, {error_msg = "set server fail"}
end
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 (run `apisix version`): 3.0.0-debian
- Operating system (run `uname -a`): Darwin Kernel Version 21.6.0
- OpenResty / Nginx version (run `openresty -V` or `nginx -V`):1.19.10-alpine
- etcd version, if relevant (run `curl
http://127.0.0.1:9090/v1/server_info`): v3.4.15-arm64
- APISIX Dashboard version, if relevant: 2.13-alpine
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run `luarocks --version`):
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]