简体   繁体   中英

How to create a real time notification system if I have a rails backend and clients which run on Angular.js?

One simple way to do this would be to have the client poll the server every 10 seconds or so, but I don't think that's the best way to go about it.

I don't want to broadcast notifications to all clients, but only to 1 client at a time.

The internet is loaded with articles on how to do this but I can't figure out which one is more appropriate for my problem.

https://github.com/websocket-rails/websocket-rails

https://github.com/ryanb/private_pub

Consider using a hosted pub/sub broker like Pusher or Realtime (the company I work for) and focus on developing your app and not managing the required real-time infrastructure.

From your Rails backend you would send the messages through the REST API and use the websocket-based JavaScript library to receive them on browser clients (subscribe).

For private messages simply subscribe each user to their own private channel (maybe using their user id).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM