From e9e53e8152b92c2daa16a27e411ebf318534b4a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Wed, 9 Feb 2022 19:54:38 +0800 Subject: [PATCH] refactor: mv the var mqtt_client_id to plugin level (#6241) --- apisix/core/ctx.lua | 5 ----- apisix/stream/plugins/mqtt-proxy.lua | 5 +++++ docs/en/latest/apisix-variable.md | 26 +++++++++++++------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/apisix/core/ctx.lua b/apisix/core/ctx.lua index a954e750..af8672d9 100644 --- a/apisix/core/ctx.lua +++ b/apisix/core/ctx.lua @@ -148,7 +148,6 @@ do balancer_ip = true, balancer_port = true, consumer_name = true, - mqtt_client_id = true, route_id = true, route_name = true, service_id = true, @@ -254,10 +253,6 @@ function _M.register_var(name, getter) error("the getter of registered var should be a function") end - if apisix_var_names[name] then - error(name .. " is registered") - end - apisix_var_names[name] = getter end diff --git a/apisix/stream/plugins/mqtt-proxy.lua b/apisix/stream/plugins/mqtt-proxy.lua index 3a285890..2c421dcc 100644 --- a/apisix/stream/plugins/mqtt-proxy.lua +++ b/apisix/stream/plugins/mqtt-proxy.lua @@ -23,6 +23,11 @@ local str_byte = string.byte local str_sub = string.sub +core.ctx.register_var("mqtt_client_id", function(ctx) + return ctx.mqtt_client_id +end) + + local schema = { type = "object", properties = { diff --git a/docs/en/latest/apisix-variable.md b/docs/en/latest/apisix-variable.md index 9591010e..d6254b82 100644 --- a/docs/en/latest/apisix-variable.md +++ b/docs/en/latest/apisix-variable.md @@ -26,18 +26,18 @@ additional variables. List in alphabetical order: -| Variable Name | Description | Example | -|------------------|-------------------------| --------- | -| balancer_ip | the IP of picked upstream server | 1.1.1.1 | -| balancer_port | the port of picked upstream server | 80 | -| consumer_name | username of `consumer` | | -| graphql_name | the [operation name](https://graphql.org/learn/queries/#operation-name) of GraphQL | HeroComparison | -| graphql_operation | the operation type of GraphQL | mutation | -| graphql_root_fields | the top level fields of GraphQL | ["hero"] | -| mqtt_client_id | the client id in MQTT protocol | | -| route_id | id of `route` | | -| route_name | name of `route` | | -| service_id | id of `service` | | -| service_name | name of `service` | | +| Variable Name | Origin | Description | Example | +|------------------|---------|--------------------| --------- | +| balancer_ip | core | the IP of picked upstream server | 1.1.1.1 | +| balancer_port | core | the port of picked upstream server | 80 | +| consumer_name | core | username of `consumer` | | +| graphql_name | core | the [operation name](https://graphql.org/learn/queries/#operation-name) of GraphQL | HeroComparison | +| graphql_operation | core | the operation type of GraphQL | mutation | +| graphql_root_fields | core | the top level fields of GraphQL | ["hero"] | +| mqtt_client_id | mqtt-proxy | the client id in MQTT protocol | | +| route_id | core | id of `route` | | +| route_name | core | name of `route` | | +| service_id | core | id of `service` | | +| service_name | core | name of `service` | | You can also [register your own variable](./plugin-develop.md#register-custom-variable).