notas de estudio pomelo

enrutamiento

Por ejemplo, una pluralidad de servidor de chat, tenemos que lidiar con mensaje diferente del servidor de enrutamiento

/*
msg结构:
{
  namespace: 'sys',
  serverType: 'gate',
  service: 'msgRemote',
  method: 'forwardMessage',
  args: [
    {
      id: 1,
      type: 0,
      compressRoute: 0,
      route: 'gate.gateHandler.getServer',
      body: [Object],
      compressGzip: 0
    },
    {
      id: 1,
      frontendId: 'connector-server-1',
      uid: null,
      settings: {}
    }
  ]
}
*/
function myRoute(session, msg, app, cb) {
    var chatServers = app.getServersByType('chat'); 
    if (!chatServers) {
     	cb(new Error('can not find chat servers.'));
		return;
    }
    cb(null, chatServers[0].id);//把所有的发往chat服务器的消息都发往第一台chat服务器中
};

app.configure('production|development', function(){
	app.route('chat', myRoute);//给chat服务器注册路由
});

canal

Para empujar mensajes al uso del servicio

  • Ingresar a un canal
remote.add = function(uid, sid, cb){
    var channel = channelService.getChannel('pomelo', true); //得到channel,true在没有的时候创建。
    if(!!channel)
        channel.add(uid, sid);//uid客户id,sid前端服务器id
};
  • canal de salida
handler.kick = function(uid, sid, name){
    var channel = channelService.getChannel(name, false);
    if (!!channel) {
        channel.leave(uid,sid);
    }
};
  • llamada RPC
app.rpc.chat.chatRemote.add(session, uid, app.get('serverId'), function(data){});
  • mensaje push
var channel = channelService.getChannel('pomelo', false);
channel.pushMessage({route:'onChat', msg:'hello'});
  • monitor del cliente de transmisión automática
pomelo.on('onChat', function(data) {});
Publicado 41 artículos originales · ganado elogios 4 · Vistas 3872

Supongo que te gusta

Origin blog.csdn.net/weixin_42487874/article/details/105400352
Recomendado
Clasificación