Real-time push update to only one user (not channel) at a time. How to do that?

北城以北 提交于 2019-12-04 03:28:01

问题


I'm creating a web app/site in which my server will push real-time update to clients some info (using Pusher api).

So, the USERS that subscribe to a CHANNEL can receive the update when the server pushes updates to this CHANNEL.

However, (because of the nature of my application) there should be only one USER that receive a real-time update at a time. In other words, an update is actually targeted to not a specific CHANNEL, but a specific USER.

My current solution is: Each CHANNEL allows only one USER so the update targeted to the CHANNEL is for that one USER. Suppose I have 500 users then I need to have 500 channels. This requires setting up a lot of channels. Does that affect performance?

Is there any better way?

===============

App Background

The app is about receiving report about a disaster and assigning a nearest agency to take over and handle the situation. Each agency will be a user of the system (will be given a username). When the server receives a report, the nearest - only one - user (from the location where the report is lodged) will receive a real-time notification from the server.


回答1:


At the moment there is not way to send a message to a user other than to have a channel per user.

My current solution is: Each CHANNEL allows only one USER so the update targeted to the CHANNEL is for that one USER. Suppose I have 500 users then I need to have 500 channels. This requires setting up a lot of channels. Does that affect performance?

This sounds exactly like the solution you are using right now e.g. the channel - and user - can be uniquely identified by channel name:

<user_name>-notification

Since channels are simply a routing mechanism there is no real overhead in having lots of channels; certainly 500 won't be any problem at all.

I'm assuming you are using private channels to ensure that only the allowed user can subscribe to their channel.



来源:https://stackoverflow.com/questions/19130772/real-time-push-update-to-only-one-user-not-channel-at-a-time-how-to-do-that

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