-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to register and use custom variable? #6702
Comments
like this: apisix/apisix/stream/plugins/mqtt-proxy.lua Lines 26 to 28 in d1d8a8e
|
thanks |
How to destroy |
see: #6656 (comment) |
you can use |
Loading the lua file is enough to register the custom variable or it must be a part of a custom plugin? |
It doesn't have to be a plugin, you can even modify the core codebase of APISIX and register some custom variables. But please make sure that you know what you're doing, or something might be broken. |
@tokers so loading the lua file is enough? |
This issue has been marked as stale due to 350 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions. |
This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time. |
Description
Referenced document: https://apisix.apache.org/zh/docs/apisix/plugin-develop/#%E6%B3%A8%E5%86%8C%E8%87%AA%E5%AE%9A%E4%B9%89%E5%8F%98%E9%87%8F
How do I use it?, "register custom variable"
Can you provide demo?
how to register
how to get
how to destroy
how to modify
and announcements
After I registered, and reload plugin, there is an error
local core = require "apisix.core"
core.ctx.register_var("a6_labels_zone2", function(ctx)
local route = ctx.matched_route and ctx.matched_route.value
if route and route.labels then
return route.labels.zone
end
return nil
end)
22826 [lua] events.lua:194: do_handlerlist(): worker-events: event callback failed; source=/apisix/admin/plugins/reload, event=PUT, pid=47 error='/usr/local/apisix/apisix/plugin.lua:113: attempt to index local 'plugin' (a number value)
stack traceback:
/usr/local/apisix/apisix/plugin.lua:113: in function 'load_plugin'
/usr/local/apisix/apisix/plugin.lua:191: in function 'load'
/usr/local/apisix/apisix/plugin.lua:300: in function 'load'
/usr/local/apisix/apisix/admin/init.lua:309: in function </usr/local/apisix/apisix/admin/init.lua:307>
[C]: in function 'xpcall'
...local/apisix//deps/share/lua/5.1/resty/worker/events.lua:185: in function 'do_handlerlist'
...local/apisix//deps/share/lua/5.1/resty/worker/events.lua:219: in function 'do_event_json'
...local/apisix//deps/share/lua/5.1/resty/worker/events.lua:361: in function 'poll'
...local/apisix//deps/share/lua/5.1/resty/worker/events.lua:380: in function <...local/apisix//deps/share/lua/5.1/resty/worker/events.lua:375>', data=1648092700, context: ngx.timer
Environment
apisix version
): 2.12.1uname -a
): Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 x86_64openresty -V
ornginx -V
): nginx version: openresty/1.19.9.1curl http://127.0.0.1:9090/v1/server_info
): version: 3.4.15, API version: 3.4luarocks --version
): 3.8.0The text was updated successfully, but these errors were encountered: