在多节点上部署socket.io应用程序

时间:2014-08-30 07:55:15

标签: node.js heroku socket.io server-farm

我在heroku上有一个应用程序,它使用socket.io进行服务器 - 客户端通信。一切都很好。但是,一旦我将我的应用程序扩展到超过1个dyno,我就会收到几个http请求错误:

can't establish a connection to the server at wss://***/socket.io/?EIO=2&transport=websocket&sid=Hky6IHdckNADdU_tAACm. socket.io.js:4520 The connection to wss://***/socket.io/?EIO=2&transport=websocket&sid=Hky6IHdckNADdU_tAACm was interrupted while the page was loading. socket.io.js:4520 can't establish a connection to the server at wss://***/socket.io/?EIO=2&transport=websocket&sid=kWymv6ItJHBcUybZAAAA. socket.io.js:4520 The connection to wss://***/socket.io/?EIO=2&transport=websocket&sid=kWymv6ItJHBcUybZAAAA was interrupted while the page was loading. socket.io.js:4520

以及负载 HTTP status 400 { code: 1, message: "Session ID unknown" }

我的socket.io正在使用redis适配器,因此应该正确共享状态。我通过连接到redis并发出以下命令来验证这一点: PSUBSCRIBE socket.io#*

由于我可以看到数据在这个频道上回传并强制执行,我假设我的socket.io redis适配器工作正常。

任何人都知道如何使用超过1个dyno使socketoku工作在heroku上?

1 个答案:

答案 0 :(得分:0)

您需要粘性负载平衡。 Socket.io有一篇很棒的文章,所以我会留给他们来解释这个话题:

https://socket.io/docs/using-multiple-nodes/