调用 pushMessage 报 app.rpcInvoke is not a function

我的 UserRemote 代码是这样子的

/**
 * 说明: 这里以用户ID 做为一个 channel
 */

const getUserChannel = (ctx, uid, sid) => {
  // 获取以用户ID为key 的 channel
  let channel = ctx.channelService.getChannel(uid, false);

  if (!channel) {
    // 创建以UID为key 的 channel
    channel = ctx.channelService.createChannel(uid);
    // 将当前用户ID及对应服务器传进去
    channel.add(uid, sid);
  }
  // todo, 判断当前用户服务器有没有变化,有的话,更新 sid
  return channel;
};


const UserRemote = function(app) {
  this.app = app;
  this.channelService = app.get('channelService');
};


UserRemote.prototype.login = function(uid, sid, data, cb) {
  const channel = getUserChannel(this, uid, sid);

  // 直接 pushMessage 就是单播,因为当前 channel 只有这一个用户
  channel.pushMessage('S2C', { name: 'xxx' }, function(){});
  cb();
};


module.exports = function(app) {
  return new UserRemote(app);
};

我在UserRemote 里面调用了 channel.pushMessage 后,收到了以下错误, 不知道啥子原因,求大神們解答

[2017-02-14 17:46:50.293] [ERROR] pomelo-rpc - [mqtt-acceptor] process rpc message error TypeError: app.rpcInvoke is not a function
    at /Users/my-server/game-server/node_modules/pomelo/lib/common/service/channelService.js:434:13
    at sendMessage (/Users/my-server/game-server/node_modules/pomelo/lib/common/service/channelService.js:437:7)
    at sendMessageByGroup (/Users/my-server/game-server/node_modules/pomelo/lib/common/service/channelService.js:444:7)
    at Channel.pushMessage (/Users/my-server/game-server/node_modules/pomelo/lib/common/service/channelService.js:331:3)
    at UserRemote.login (/Users/my-server/game-server/app/servers/user/remote/userRemote.js:30:11)
    at Dispatcher.pro.route (/Users/my-server/game-server/node_modules/pomelo-rpc/lib/rpc-server/dispatcher.js:52:10)
    at Acceptor.cb (/Users/my-server/game-server/node_modules/pomelo-rpc/lib/rpc-server/gateway.js:22:16)
    at processMsg (/Users/my-server/game-server/node_modules/pomelo-rpc/lib/rpc-server/acceptors/mqtt-acceptor.js:138:12)
    at Connection.<anonymous> (/Users/my-server/game-server/node_modules/pomelo-rpc/lib/rpc-server/acceptors/mqtt-acceptor.js:62:11)
    at emitOne (events.js:96:13)
标签: pomelo 开发求助
zernmal 在 2-14 17:56发布 分享到 weibo
1 回复
#1 {1} fantasyni 2-14 18:46 回复

检查下 adminServers.json 是不是某个服务器没有注册成功

zernmal 2-14 22:13 回复

嗯,那里本来只有 connector 的配置,我加上 user 的就可以了:

[{
    "type": "connector",
    "token": "bsdfvninlmdpfghomadfg945345fsdfww"
},{
    "type": "user",
    "token": "iikasdfasdfasdfaser53354fw45345sdf"
}]

谢谢大神

回到顶部