V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
BeginMan
V2EX  ›  Node.js

关于 socket.io 负载均衡问题

  •  
  •   BeginMan · 2015-07-09 11:36:31 +08:00 · 4212 次点击
    这是一个创建于 3429 天前的主题,其中的信息可能已经有所发展或是发生改变。

    关于socket.io 负载均衡问题,参考官网Using multiple nodes:http://socket.io/docs/using-multiple-nodes/, 我设置如下:

    var io = require('socket.io').listen(8891);
    
    var port=6379;
    var host='localhost';
    var pwd = '******';
    
    var redis = require('redis').createClient;
    var adapter = require('socket.io-redis');
    var pub = redis(port, host, { auth_pass: pwd });
    var sub = redis(port, host, { detect_buffers: true, auth_pass: pwd });
    io.adapter(adapter({ pubClient: pub, subClient: sub }));
    

    关于这个adapter 总是报错:

    io.adapter(adapter({ pubClient: pub, subClient: sub }));
       ^
    TypeError: undefined is not a function
    at Object.<anonymous> (/home/team/project/ylx/sync-svc/sync-server_8891.js:18:4)
    at Module._compile (module.js:462:26)
    at Object.Module._extensions..js (module.js:480:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:503:10)
    at startup (node.js:132:16)
    at node.js:817:3
    

    我的socket.io版本0.9.17,其他版本见下方:

    ├─┬ [email protected]
    │ ├── [email protected]
    │ └── [email protected]
    ├── [email protected]
    ├─┬ [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ └─┬ [email protected]
    │   ├─┬ [email protected]
    │   │ └── [email protected]
    │   ├── [email protected]
    │   ├─┬ [email protected]
    │   │ ├── [email protected]
    │   │ ├── [email protected]
    │   │ ├── [email protected]
    │   │ └── [email protected]
    │   └── [email protected]
    └─┬ [email protected]
      ├── [email protected]
      ├─┬ [email protected]
      │ └─┬ [email protected]
      │   ├── [email protected]
      │   └── [email protected]
      ├── [email protected]
      ├─┬ [email protected]
      │ ├─┬ [email protected]
      │ │ └── [email protected]
      │ ├── [email protected]
      │ └─┬ [email protected]
      │   ├── [email protected]
      │   ├── [email protected]
      │   ├── [email protected]
      │   ├── [email protected]
      │   └── [email protected]
      └── [email protected]
    

    对于此类问题求解决方案~

    2 条回复    2015-07-09 12:04:35 +08:00
    BeginMan
        1
    BeginMan  
    OP
       2015-07-09 12:02:18 +08:00
    刚才测试了下,还是版本的问题。
    BeginMan
        2
    BeginMan  
    OP
       2015-07-09 12:04:35 +08:00
    如果是不升级的话 socket.io 0.9.x 就不能multiple nodes 么????
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1074 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 22:34 · PVG 06:34 · LAX 14:34 · JFK 17:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.