You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.0 KiB
Lua

local skynet = require "skynet"
require "skynet.manager"
local setting_template = require "settings"
local skynet_node_name = ...
local CMD = {}
local pool = {}
local maxconn
local function getconn(uid)
local db
if not uid or maxconn == 1 then
db = pool[1]
else
db = pool[(uid - 1) % maxconn + 1]
end
assert(db)
return db
end
local function start()
local settings = setting_template.db_cnf[skynet_node_name]
INFO("redismq consumer 启动", skynet_node_name, inspect(settings))
maxconn = tonumber(settings.redismq_maxinst) or 1
for i = 1, maxconn do
local consumer_slave = skynet.newservice("consumer_slave", i)
skynet.call(consumer_slave, "lua", "start", settings.redismq_cnf)
table.insert(pool, consumer_slave)
end
end
skynet.start(function()
start()
skynet.dispatch("lua", function(_, _, cmd, ...)
local f = assert(CMD[cmd], cmd .. "not found")
skynet.retpack(f(...))
end)
skynet.register("." .. SERVICE_NAME)
end)