darkSheep404 opened a new issue, #12103:
URL: https://github.com/apache/apisix/issues/12103
### Description
i want to base on some condition to routing to different service
when i use `ctx.upstream_id = conf.upstream_id` it will routing to new
upstream
but when i use `ctx.service_id = conf.service_id `, it still routing to old
version
Cause we have plugins on service level , routing to new service will be
better than routing to a new upstream
May I know how can we mannually change service to annother service in plugin
code ?
```lua
local core = require("apisix.core")
local upstream = require("apisix.upstream")
local schema_def = require("apisix.schema_def")
local expr = require("resty.expr.v1")
local plugin_name = "custom-traffic-split"
local schema = {
type = "object",
properties = {
upstream_id = schema_def.id_schema,
service_id = schema_def.id_schema
}
}
local _M = {
version = 0.1,
priority = 966,
name = plugin_name,
schema = schema
}
function _M.check_schema(conf)
return core.schema.check(schema, conf)
end
function _M.access(conf, ctx)
if not conf then
return
end
--
local gary_release = core.request.header(ctx, "gary_version")
if not gary_release then
return
end
--
if conf.upstream_id then
ctx.upstream_id = conf.upstream_id
return
end
if conf.service_id then
ctx.service_id = conf.service_id
return
end
end
return _M
```
### Environment
- APISIX version (run `apisix version`):
- Operating system (run `uname -a`):
- OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
- etcd version, if relevant (run `curl
http://127.0.0.1:9090/v1/server_info`):
- APISIX Dashboard version, if relevant:
- 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]