PubNub或Pusher并将数据存储在我自己的服务器上 [英] PubNub or Pusher and storing data on my own server

查看:118
本文介绍了PubNub或Pusher并将数据存储在我自己的服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个移动应用程序,用户可以通过聊天(用户只对用户,而不是聊天室)与对方交谈。

I have a mobile application where users can talk to each others via a chat (user to user only, not chatroom).

今天,一切都是同步的。我们正在考虑将解决方案转换为更实时的方式,可能使用PubNub或Pusher。

Today, everything is synchronous. We are considering switching the solution to something more "real time", maybe using PubNub or Pusher.

我们想知道最好的方法,因为我们的服务器将需要存储每封已发送的邮件。

We are wondering about the best way to do it, given that our server will need to store every sent message.

我们的想法:


  • 每个移动应用都会使用用户ID作为频道名称来创建频道。

  • 此频道将用于移动应用/服务器通信。

我的问题是关于服务器,今天我们有一个Nginx / PHP后端。我们希望我们的服务器能够监听所有用户频道,因为我们需要在我们自己的服务器上存储用户发送的消息。

My problem is regarding the server, today we have a Nginx/PHP backend. We would like our server to be able to listen all user channels as we need to store users sent messages on our own server.

对于用户与用户之间的沟通,我们正在考虑在消息中创建我们自己的协议。例如。如果用户111想要向用户222发送hello,他可以发布to:222 hello,这将由服务器检索。

For user to user communication, we are thinking to create our own protocol inside the messages. Eg. if user 111 wants to send "hello" to user 222, he could publish "to:222 hello", which would be retrieved by the server.

服务器,在接收此命令会将from:111 hello推送到他自己的频道(这将是222)。

The server, upon receiving this command would push "from:111 hello" to his own channel (which would be 222).

我看到这个设计的问题是我们的服务器需要打开尽可能多的频道,因为我们的数据库中有总用户数。

The problem I see with this design is that our server would need to open as many channels as we have total users in our database.

我没有看到更好的方法。

I do not see a better way to do it.

推荐答案

关于如何做到这一点的建议,请尝试下一步:

As suggestion about how it can be done, try next thing:


  1. 在他们自己的频道订阅客户

  2. 订阅服务器在某个特殊频道上使用常量名称

  3. 如果客户 A 想要发送消息到客户端 B 它应该将其发送到之前订阅的服务器的频道。也许你必须以特殊格式发送它,这将允许识别发件人和收件人。

  4. 服务器解析来自客户端 A 的格式化邮件并将其发送到频道 B 订阅的频道。

  1. subscribe clients on their own channels
  2. subscribe server on some special channel with constant name
  3. if client A want to send message to client B it should send it into channel at which server subscribed before. Maybe you will have to send it in special format, which will allow to identify sender and recipient.
  4. Server parse formatted message from client A and send it into the channel at which channel B subscribed.

所以基本上服务器只在一个频道上订阅并从中接收消息,解析并发送到收件人的频道(您不必在要发送邮件的频道上订阅)。

So basically server subscribed only on one channel and receive messages from it, parse and send into recipient's channel (you don't have to be subscribed on channel into which you want to send message).

这篇关于PubNub或Pusher并将数据存储在我自己的服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆