agusjanardana opened a new issue, #10807: URL: https://github.com/apache/apisix/issues/10807
### Description Hello, I'm just learning Lua scripting for gateway needs. Maybe this is clear here, but I'm still looking for the right solution. According to the documentation from Resty Redis (https://github.com/openresty/lua-resty-redis) and the results of my assessment, it turns out that Redis cannot be used in the body_filter_by_lua (CMIIW) phase. So i made 2 plugins that will work together. My problem here is: 1. I don't have access to changing the backend, whether adding or removing services. 2. I want to change the response of a service soap. The output results will be brought to Redis. 3. To get the response body, as far as I know, it can be done in body_filter. Here I want to get one response, let's say response A. 4. Response A will be stored in Redis. I have made 2 plugins, to transform and get responses from soap and another plugin to connect to Redis and save it. My route will use 2 of this plugins to do that work. Here's what i worked before : **A. Plugin Transform Response** ` local function extract_session_id(xml_string) local pattern = "<GetSessionIdResponse[^>]*>(.-)</GetSessionIdResponse>" -- string match local session_id = string.match(xml_string, pattern) -- print log if session_id then ngx.log(ngx.INFO, "Session ID: ", session_id) return session_id else ngx.log(ngx.ERR, "Failed to extract Session ID from XML response") return nil end end function _M.body_filter(conf, ctx) local body = core.response.hold_body_chunk(ctx) if not body then return core.log.warn("failed to hold response body chunk") end -- Extract and store session ID in shared memory dictionary local sessionid = extract_session_id(body) ctx.sessionid = sessionid -- if sessionid then -- ngx.arg[1] = sessionid -- end end ` **B. Plugin save redis** ` function _M.access(conf, ctx) -- 2. Save session ID to Redis local redis_cli = redis_client(conf.redis) if not redis_cli then return json_response(500, { message = "Session storage is unavailable" }) end core.log.warn(ctx.sessionid) redis_cli:set("new", ctx.sessionid) return ctx.sessionid end ` My question : 1. I have set the priority, plugin A priority is 1000 and plugin B is 500, but why plugin B always running first? it make my service error. I have tried each plugin independently and hardcode variabel, its work. 2. As far as i know, context can save a value. Can the value saved in ctx like i did above? and is the value will share accross the plugin that i used in a route? 3. Is there any other solution to my problem? I dont have access to the backend, so what i can do is from the api gateway. Thanks anyway. ### Environment - APISIX version (run `apisix version`): 3.6 - Operating system (run `uname -a`): Mac OS Ventura - OpenResty / Nginx version (run `openresty -V` or `nginx -V`): openresty/1.21.4.2 - 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]
