简体   繁体   English

如果我有Rails后端并且在Angular.js上运行的客户端,如何创建实时通知系统?

[英]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. 一种简单的方法是让客户端每隔10秒左右对服务器进行一次轮询,但是我认为这不是解决问题的最佳方法。

I don't want to broadcast notifications to all clients, but only to 1 client at a time. 我不想向所有客户端广播通知,而一次仅向1个客户端广播。

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/websocket-rails/websocket-rails

https://github.com/ryanb/private_pub 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. 考虑使用托管的发布/订阅代理,例如PusherRealtime (我工作的公司),并专注于开发应用程序而不管理所需的实时基础结构。

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). 从Rails后端,您将通过REST API发送消息,并使用基于websocket的JavaScript库在浏览器客户端(订阅)上接收消息。

For private messages simply subscribe each user to their own private channel (maybe using their user id). 对于私人消息,只需为每个用户订阅他们自己的私人频道(也许使用其用户ID)即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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