@@ -25,32 +25,10 @@ local ngx = ngx
2525local core = require (" apisix.core" )
2626
2727local _M = {
28- events_module = nil ,
2928}
3029
31- _M .EVENTS_MODULE_LUA_RESTY_WORKER_EVENTS = ' lua-resty-worker-events'
32- _M .EVENTS_MODULE_LUA_RESTY_EVENTS = ' lua-resty-events'
33-
34-
35- -- use lua-resty-worker-events
36- local function init_resty_worker_events ()
37- _M .events_module = _M .EVENTS_MODULE_LUA_RESTY_WORKER_EVENTS
38-
39- local we = require (" resty.worker.events" )
40- local shm = ngx .config .subsystem == " http" and " worker-events" or " worker-events-stream"
41- local ok , err = we .configure ({shm = shm , interval = 0.1 })
42- if not ok then
43- error (" failed to init worker event: " .. err )
44- end
45-
46- return we
47- end
48-
49-
5030-- use lua-resty-events
5131local function init_resty_events ()
52- _M .events_module = _M .EVENTS_MODULE_LUA_RESTY_EVENTS
53-
5432 local listening = " unix:" .. ngx .config .prefix () .. " logs/"
5533 if ngx .config .subsystem == " http" then
5634 listening = listening .. " worker_events.sock"
@@ -81,19 +59,7 @@ function _M.init_worker()
8159 end
8260
8361 _M .inited = true
84-
85- local conf = core .config .local_conf ()
86- local module_name = core .table .try_read_attr (conf , " apisix" , " events" , " module" )
87- or _M .EVENTS_MODULE_LUA_RESTY_WORKER_EVENTS
88-
89- if module_name == _M .EVENTS_MODULE_LUA_RESTY_EVENTS then
90- -- use lua-resty-events as an event module via the apisix.events.module
91- -- key in the configuration file
92- _M .worker_events = init_resty_events ()
93- else
94- -- use lua-resty-worker-events default now
95- _M .worker_events = init_resty_worker_events ()
96- end
62+ _M .worker_events = init_resty_events ()
9763end
9864
9965
10571function _M .event_list (self , source , ...)
10672 -- a patch for the lua-resty-events to support event_list
10773 -- this snippet is copied from the lua-resty-worker-events lib
108- if self .events_module == _M .EVENTS_MODULE_LUA_RESTY_EVENTS then
109- local events = { _source = source }
110- for _ , event in pairs ({... }) do
111- events [event ] = event
112- end
113- return setmetatable (events , {
114- __index = function (_ , key )
115- error (" event '" .. tostring (key ).. " ' is an unknown event" , 2 )
116- end
117- })
74+ local events = { _source = source }
75+ for _ , event in pairs ({... }) do
76+ events [event ] = event
11877 end
119-
120- -- the lua-resty-worker-events has a built-in event_list implementation
121- return self .worker_events .event_list (source , ... )
78+ return setmetatable (events , {
79+ __index = function (_ , key )
80+ error (" event '" .. tostring (key ).. " ' is an unknown event" , 2 )
81+ end
82+ })
12283end
12384
12485
@@ -127,13 +88,4 @@ function _M.post(self, ...)
12788end
12889
12990
130- function _M .get_healthcheck_events_module (self )
131- if self .events_module == _M .EVENTS_MODULE_LUA_RESTY_EVENTS then
132- return " resty.events"
133- else
134- return " resty.worker.events"
135- end
136- end
137-
138-
13991return _M
0 commit comments