C# 观察者模式消息过滤
我正在编写一个视频 cms,并希望所有用户在进入时立即显示新资源。 如果我是对的,Facebook 会实时更新其墙页。因此,当我向朋友发布内容时,它会立即显示在他的墙上。正如他们所说,实时网络。 我想知道你是怎么做到的?不是客户端-服务器通信的技术,而是服务器上发生的事情。 我了解观察者模式的原理。 但墙实际上是对消息表的查询。 观察者如何知道用户对什么查询感兴趣? 它是否保存所有连接用户的所有查询并在有新内容出现时重新运行它。 我相信 Google-realtime 就是这样工作的。 谢谢你帮助我。
I'm writing a video cms and want all my users to have new assets displayed immediately as they come in.
If I'm right, facebook updates its wall-page in realtime. So when I post something to a friend it immediately displays on his wall. The realtime web, as they say.
I wonder how you do that? Not the technology of client-server-communication, but what goes on on the server.
I understand the principles of the observer-pattern.
But a wall is in fact a query on a table of messages.
How does the observer know what query a user is interested in?
Does it hold all the query's of all connected users and reruns it when something new comes in.
I believe Google-realtime works that way to.
Thank you for helping me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您打开 Facebook 时,在浏览器中打开脚本时间线以查看页面上正在执行哪些脚本。您会注意到每秒执行多次轮询脚本。因此页面每秒会多次查看缓存,以查看是否有任何可以显示的新信息。
http://www.ajaxwith.com/Poll-vs-Push-Technology.html - 这应该为您提供该主题的背景知识。
When you open facebook, open the script timeline in your browser to see what scripts are executing on the page. You'll notice that there is a polling script being executed several times a second. So the page is looking at the cache several times a second to see if there is any new information that can be displayed.
http://www.ajaxwith.com/Poll-vs-Push-Technology.html - this should give you a background on the subject.
Facebook 使用 AJAX 和 JavaScript 计时器在后台轮询以查找任何更改。其他网站使用相同类型的功能来更新页面中嵌入的股票报价等。它并不是真正立即更新,而是按照 JavaScript 计时器命中其服务器的频率进行更新。这是因为 Web 浏览器使用 HTTP,这是一种请求/响应协议。浏览器不会显示任何不是对浏览器发起的请求的直接响应的内容;无法直接将内容从网络服务器发送到浏览器。
Facebook uses AJAX and a JavaScript timer that polls in the background looking for anything that's changed. Other sites use the same type of functionality to update stock quotes embedded in the page, etc. It's not truly updating immediately, it's updating as frequently as the JavaScript timer hits their server. This is because web browsers use HTTP, which is a request/response protocol. A browser won't display anything that's not as a direct response to a request initiated by the browser; there's no way to just send content directly to the browser from your webserver.