Node.js实现网络负载均衡器:LoadBalancer.js

jopen 10年前

LoadBalancer.js是一个sticky-session TCP 负载均衡器,专门优化用于实时框架(包含支持HTTP长轮询fallbacks)。它从一个指定端口的捕获原始TCP连接,并将其转发到不同的目标(定义成主机和端口的组合)。

module.exports.run = function (balancer) {    balancer.addMiddleware(balancer.MIDDLEWARE_CONNECTION, function (socket, next) {      // You can use whatever logic you want in order to decide whether or       // not to process this connection      if (...) {        // Allow connection to go through        next();      } else {        // Block connection        next('Blocked connection from client with IP: ' + socket.remoteAddress);      }    });  };

项目主页:http://www.open-open.com/lib/view/home/1420507390859