123456789101112131415161718192021222324252627282930313233343536373839 |
- -- 消息队列子系统
- local skynet = require "skynet"
- require "skynet.manager"
- local logger = require "logger"
- local mq = skynet.localname(".mq")
- local CMD = {}
- local MODULE = {}
- function MODULE.list_command_interests() return CMD end
- function MODULE.monitor(character)
- -- 在各模块 ready 接口执行之后
- character.monitor('ready', function()
- -- 注册到消息中心
- skynet.call(mq, "lua", "subscribe", character.uid)
- -- 有些模块需要确切的知道,离线消息处理完毕;
- local co = coroutine.running()
- skynet.fork(function()
- character.dispatch("mq.ready")
- skynet.wakeup(co)
- end)
- skynet.wait(co)
- end)
- -- 在各模块 saybye 接口执行之前
- character.monitor('disconnect', function()
- -- 从消息中心注销自己
- skynet.call(mq, "lua", "unsubscribe", character.uid)
- end)
- -- logger.trace("mq.monitor")
- end
- function CMD.publish(character, signame, ...)
- logger.trace("publish: %s", signame)
-
- character.dispatch(signame, ...)
- end
- return MODULE
|