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

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

问题描述

简要说明

那么,既然多天我一直在寻找的答案,这个问题,但似乎有答案为如何创建一个推送通知服务器和这样的问题。我使用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.

详细信息

OK,所以,让我们说我有一个应用程序,其中有一个聊天服务(只是一个例子,这是实际的事情是大的,你可能已经猜到了)。一个人在一个房间发送一条消息,并都在房间里的人得到通知。但我要的是一个有状态聊天 - 也就是说,我要的信息存储在数据存储中。在此处,麻烦来了。在数据库中存储的信息,后来逢人便说:嘿,有你的消息。当我们需要的实时活动的只是一个应用程序的一部分。这似乎很容易。当整个应用程序是基于实时通信该怎么办?除此之外,我也想有一个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

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

希望能对你有所帮助。 :)

Hope you can be of help. :)

更新

我想我忘了强调我的问题的一个重要组成部分。如何实现发布 - 订阅系统? (注:我不想实际code,我会管理我自己,只是如何去这样做正是我需要一些帮助)。问题是,我写code时得到相当猛然一惊 - 做如何(我的困惑是从这个问题本身比较明显)。能否请您提供一些参考阅读或一些建议就如何使用这个东西了么?

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. 我们也有一个RESTful接口来访问实时的服务器,以获得当前的聊天记录以懒惰的方式。

和要构建您的系统是这样的:

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.

在此架构中,一切都在你的意思方向没关系。我的意思是数据存储是由服务器连接来访问数据,也许要查询的身份验证客户端凭据,可能读取用户preferences等。

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?

您实时服务器是客户端的服务器;但它也为数据层,或数据库服务器的客户端,如果我们preFER一个更常见的命名。因此,我们已经知道,没有什么东西是从一个客户端停止服务器。那么,为什么不能我们的数据库系统和基于REST的系统也是客户呢?它们连接到服务器实时连接浏览器和其他客户端相同的方式。让他们享受被人之一。 :)

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天全站免登陆