Websocket multiple Channels vs. One Channel + Server Side handling [GroupChat]

不问归期 提交于 2019-12-10 13:36:48

问题


Let's say we want to create private chat rooms, where user can chat in small groups. A user can join multiple / x groups. In each case, I need to create a unique group on the server and subscribe user to these. Which approach is the recommended / more performant way:


[1] On the server side, I create a Room class and add new room channels for each group chat, e.g. "chats/room-asdhqk1", "chats/room-fwuefhw1", "chats/room-awsdhqwd2". Now, some specified users can join this channel and are added to the group client list. On the Client side, the users are subscribed to the group channels they were added to.

Problem: When a user is in x channels, I need to subscribe him into these x channels after side load. Good: Broadcasting to a specific group can be done through the group channel name and all users subscribed to that channel will automatically receive the message, because they have subscribed to the channel within the js part.


[2] Each user gets his own channel, e.g. "notifications/user-1", "notifications/user-2"... . On the server side, I create groups in a Rooms Class (no channels). A user can be added to a specific room by adding him to a sublist of the rooms list. When they chat with each other, the server iterates over the subscribed users of a group chat and sends to each user notification channel the message - no group channel here at all - only per user channels.

Problem: I cannot broadcast a message easily, I need to iterate over each subscribed user and send the message to his notification-channel. In addition, I cannot use the "publish" method in the frontend to easily publish messages to a channel, because users are separated in different channels.

Good: In the end, the broadcasting method would do the same: iterating over a subscriber list. For sending Messages, I could easily implement an RPC Method that does the same as the "publish" method - looking up subscribed users of a group and send the message to them. With this approach, the user does not need to connect to x channels on the client side, he just has one channels that handles all.

(I know that for the second approach, a pusher is required (e.g zmq)).


What are your opinions ? I think that the second one is better, because I don't have to subscribe the user on the client side to x - channels. This would not be performant, if a user needs to first connect to e.g. 500 Channels.

Regards.

来源:https://stackoverflow.com/questions/32943299/websocket-multiple-channels-vs-one-channel-server-side-handling-groupchat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!