I want to check that i've got my knowledge the right way round with using pubsub to gather notifications for a specific user in a Node.js/socket.io environment.

我想通过使用pubsub在Node.js / socket.io环境中为特定用户收集通知来检查我的知识是否正确。

Here's my setup:

这是我的设置:

  • Main application is written in PHP over Codeigniter. Auth is handled using Ion_Auth for CI (Session etc)
  • 主要应用程序是用PHP编写的Codeigniter。使用Ion_Auth for CI(会话等)处理Auth
  • Realtime (currently just notifications) is handled with Node.js and Socket.io
  • 实时(当前只是通知)由Node.js和Socket.io处理
  • Authenticated users can invite friends to "groups" - invite will send both email and internal notification if invitee already has account
  • 经过身份验证的用户可以邀请朋友加入“群组” - 如果被邀请者已经拥有帐户,邀请将发送电子邮件和内部通知
  • Authenticated users can leave comments, perform actions on shared content. Both will result in a notification to all subscribed users of that content.
  • 经过身份验证的用户可以发表评论,对共享内容执行操作。两者都将导致向该内容的所有订阅用户发出通知。

I believe the correct way to handle this, is for each user to be subscribed to a notification channel. This channel contains every notification for every user, which is pushed to the channel by a publish event fired any time we do one of the above actions. The subscription then checks this channel for specific data related to the user session, i.e.:

我相信处理这个问题的正确方法是让每个用户订阅一个通知渠道。此频道包含每个用户的每个通知,只要我们执行上述操作之一,就会通过发布事件将其推送到频道。然后,订阅检查该信道以获得与用户会话相关的特定数据,即:

  • For notifications related to invites, the published event would contain some uniquely identifying user data, and we would check for that.
  • 对于与邀请相关的通知,已发布的事件将包含一些唯一标识的用户数据,我们将检查该事件。
  • for notifications related to a specific piece of content, we would check the channel for published events containing identifying markers for that content.
  • 对于与特定内容相关的通知,我们会检查频道是否包含该内容的识别标记的已发布事件。

Is this the right way to do it? I'm fairly new to socket.io, node.js and pubsub, but this seems to make sense to me. The part which is throwing me, is that we should be pushing events to the clients, rather than the client pulling events from the server. This solution seems to do both.

这是正确的方法吗?我对socket.io,node.js和pubsub相当新,但这似乎对我有意义。抛弃我的部分是我们应该将事件推送给客户端,而不是客户端从服务器中提取事件。这个解决方案似乎同时做到了。

If there is a simpler solution (i.e. something more native to socket.io) i'd appreciate some insight. All I can really find in the way of tutorials or examples is the same chat client writeup over and over...

如果有一个更简单的解决方案(即socket.io更本地的东西),我会很感激一些见解。在教程或示例中我真正能找到的是同一个聊天客户端的一遍又一遍的写作......

Edit: Alternatively, would it be more practical to maintain a hash of all connected client ids alongside their corresponding user id, then when a new message comes in, emit that message to the specific client using var socket = hash[userID]; socket.emit(message);

编辑:或者,维护所有连接的客户端ID的散列以及相应的用户ID是否更实际,然后当有新消息进入时,使用var socket = hash [userID];将该消息发送到特定客户端; socket.emit(消息);

Anyone got any thoughts as to potential bottlenecks in this case? The site could potentially have many thousands of concurrent users being updated about multiple events.

在这种情况下,有人对潜在的瓶颈有任何想法吗?该站点可能会有数千个并发用户正在更新多个事件。

1 个解决方案

#1


0

I suggest not implementing the PubSub yourself. I had to do that kind of broadcast once and used RabbitMQ to handle the connections and routing (that includes broadcast).

我建议不要自己实现PubSub。我不得不做一次这样的广播,并使用RabbitMQ来处理连接和路由(包括广播)。

Real time messaging to a browser is done using reverse Ajax calls (long held http connections, see Comet on Wikipedia)

使用反向Ajax调用实现对浏览器的实时消息传递(长期持有的http连接,请参阅维基百科上的Comet)

See RabbitMQ server and libraries for Node

请参阅RabbitM的RabbitMQ服务器和库

Rabbit MQ offers many advantage:

Rabbit MQ提供了许多优势:

  • The client will alway be able to post a message as long as RabbitMQ is running.
  • 只要RabbitMQ正在运行,客户端就可以发布消息。
  • You will be able to scope your server easily by starting another instance of your application server whenever you need more throughput (scale out).
  • 无论何时需要更多吞吐量(向外扩展),您都可以通过启动应用程序服务器的另一个实例来轻松扩展服务器的范围。
  • Messages sent to RabbitMQ can be persisted.
  • 发送到RabbitMQ的消息可以保留。
  • Posting messages to RabbitMQ can be done inside a transaction.
  • 向RabbitMQ发送消息可以在事务内部完成。
  • Easy server insterface to manage your queues and exchanges.
  • 简单的服务器界面来管理您的队列和交换。

更多相关文章

  1. 设计多级用户权限系统
  2. 使用 PHP usort() 通过用户自定义的比较函数对数组进行排序
  3. 跟踪PHP中的登录用户
  4. WordPress注册和用户注册是分开的
  5. PHP联系表格给用户发送随机确认号码
  6. 仅在LARAVEL或AJAX中提交表单时,无需用户身份验证即可将文件上载
  7. PHP开发微信支付代码及支付通知处理
  8. 如何区分socket.io聊天中的Symfony用户角色/组
  9. php微信网页授权获取用户信息

随机推荐

  1. hust校赛d题 PHP is the best language i
  2. 存储用户所需语言的最佳方式
  3. PHP中使用cURL实现Get和Post请求的方法
  4. 一些PHP相关的数据比较
  5. Windows7搭建Apache本地服务器+PHP环境
  6. 如何为$ wpdb-> insert创建一个包含colum
  7. 为什么cron工作不是从浏览器工作,但从终端
  8. php连接mysql的三种方法
  9. 如何递归将特色图像应用于Wordpress中的
  10. 将Ajax div内容存储在PHP变量中