Node.js實現網絡負載均衡器:LoadBalancer.js
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); } }); };
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!