I want to host a chat application(Socketio, Node) in heroku. Need to spawn using throng

时间:2017-11-16 13:15:47

标签: node.js heroku socket.io

I am trying to use Socketio, throng to use WEB_CONCURRENCY environment variable and spawn as OOTB behavior of heroku.

How do we make sure the socket polling always goes to one worker node? Do we need to use any sticky session module?

PS: I have enabled session affinity in heroku. So the polling is not going to all dynos.

But in the same dyno, for different workers, from the same client socket polling is not going to the same worker.

Anyone has a sample code or approach? I am not able to find any sample logic in internet.

Thanks so much in advance.

1 个答案:

答案 0 :(得分:-1)

根据我的理解,您希望根据客户端的原始地址来路由客户端,您可以设置多个节点集群。

是的,您需要使用粘性会话 - https://github.com/indutny/sticky-session

如果你想播放'那么你需要一个适配器(https://github.com/socketio/socket.io-adapter)来在客户端之间传递消息。