如何在服务器上建模推送通知 [英] How to model Push Notifications on server

查看:21
本文介绍了如何在服务器上建模推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简要说明:

好吧,很多天以来我一直在寻找这个问题的答案,但似乎有如何创建推送通知服务器"等问题的答案.我正在使用 node.js 并且使用 sock.js 很容易创建"一个推送通知服务器(我听说 socket.io 与 sock.js 相比并不好).到这里都没问题.但我想要的是如何建模这样的服务器.

Well, since many days I've been looking for an answer to this question but there seems to be answers for 'How to create a Push Notification Server' and like questions. I am using node.js and it's quite easy to 'create' a push notification server using sock.js (I've heard socket.io isn't good as compared to sock.js). No problem till here. But what I want is how to model such a server.

详情:

好的,那么,假设我有一个应用程序,其中有一个聊天服务(这只是一个例子,实际的事情正如你可能已经猜到的那样大).一个人在房间里发送消息,房间里的所有人都会收到通知.但我想要的是有状态"聊天——也就是说,我想将消息存储在数据存储中.麻烦就来了.将消息存储在数据库中,然后告诉每个人嘿,有一条消息给你".当我们只需要应用程序的一部分的实时活动时,这似乎很容易.整个app都是基于实时通讯的怎么办?除此之外,我还想要一个RESTful api.

OK, so, let's say I've an application where there's a chat service (just an example this is, actual thing is big as you might have guessed). A person sends a message in a room and all the people in the room get notified. But what I want is a 'stateful' chat - that is, I want to store the messages in a data store. Here's where the trouble comes. Storing the message in the database and later telling everyone that "Hey, there's a message for you". This seems easy when we need the real-time activity for just one part of the app. What to do when the whole app is based on real-time communication? Besides this, I also want to have a RESTful api.

我的解决方案(我不太满意)

我想做的是:(当然是在服务器端)

What I thought of doing was this: (on the server side of course)

                 Data Store
                     ||
                 Data Layer (which talks to data store)
                     ||
            ------------------
            |                |
     Real-Time Server   Restful server

在这里,实时服务器侦听数据层发布的有趣事件.每当发生有趣的事情时,服务器都会通知客户端.但是哪个客户?- 这是我方法的问题

And here, the Real-time server listens to interesting events that the data-layer publishes. Whenever something interesting happens, the server notifies the client. But which client? - This is the problem with my method

希望能帮到你.:)

更新:

我想我忘了强调我的问题的一个重要部分.如何实现发布订阅系统?(注意:我不想要实际的代码,我会自己管理;只是如何去做是我需要帮助的地方).问题是我在编写代码时很困惑——该怎么做(从这个问题本身就很明显我的困惑).能否请提供一些参考阅读或有关如何开始这件事的一些建议?

I think I forgot to emphasize an important part of my question. How to implement a pub-sub system? (NOTE: I don't want the actual code, I'll manage that myself; just how to go about doing it is where I need some help). The problem is that I get quite boggled when writing the code - what to do how (my confusion is quite apparent from this question itself). Could please provide some references to read or some advice as to how to begin with this thing?

推荐答案

我不确定我是否理解正确;但我会总结一下我是如何阅读的:

I am not sure if I understood you correctly; but I will summarize how I read it:

  1. 我们有一个实时聊天服务器,它使用套接字连接向所有连接的客户端发布新消息.
  2. 我们有一个数据库,用于保存聊天记录.
  3. 我们还有一个安静的界面来访问实时服务器,以更懒惰的方式获取当前的聊天记录.

并且您想以这种方式构建您的系统:

And you want to architect your system this way:

在上图中,我用紫色曲线圈出的组件希望像所有其他客户端一样进行更新.我对吗?我不知道你所说的数据层"是什么意思,但我认为它是一个守护进程,它将写入数据库并为其他组件连接数据库.

In the above diagram, the components I circled with purple curve wants to be updated like all other clients. Am I right? I don't know what you meant with "Data Layer" but I thought it is a daemon that will be writing to database and also interfacing database for other components.

在这个架构中,一切都朝着你想要的方向发展.我的意思是 DataStore 由服务器连接以访问数据,可能是查询客户端凭据以进行身份​​验证,可能是读取用户首选项等.

In this architecture, everything is okay in the direction you meant. I mean DataStore is connected by servers to access data, maybe to query client credentials for authentication, maybe to read user preferences etc.

对于你对这些组件的其他期望,我的意思是允许这些组件像连接的客户端一样更新,你为什么不让它们也成为客户端?

For your other expectation from these components, I mean to allow these components to be updated like connected clients, why don't you allow them to be clients, too?

您的实时服务器是客户端的服务器;但如果我们更喜欢更常见的命名,它也是数据层或数据库服务器的客户端.所以我们已经知道没有什么可以阻止服务器成为客户端.那么,为什么我们的数据库系统和restful系统不能也是客户端呢?以与连接浏览器和其他客户端相同的方式将它们连接到实时服务器.让他们享受成为其中一员的乐趣.:)

Your realtime server is a server for clients; but it is also a client for data layer, or database server, if we prefer a more common naming. So we already know that there is nothing that stops a server from being a client. Then, why can't our database system and restful system also be clients? Connect them to realtime server the same way you connect browsers and other clients. Let them enjoy being one of the people. :)

我希望我没有完全理解错误,这对于这个问题是有道理的.

I hope I did not understand everything completely wrong and this makes sense for the question.

这篇关于如何在服务器上建模推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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