彗星 vs pubsub..?

发布于 2024-08-03 18:03:02 字数 36 浏览 7 评论 0原文

我可以知道这两种方法有什么不同吗?能用通俗的话解释一下吗?

may i know what is the different between these 2 approach ? can explain in lay man terms?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩心不撩汉 2024-08-10 18:03:02

Comet 是一种将实时数据推送到网络浏览器的技术 - 因此页面可以不断更新。有关更多详细信息,请参阅此页面关于 Comet

Pub/Sub(或发布/订阅)与 Comet 没有什么不同,它是一种告诉 Comet 服务器您想要接收(订阅)哪些数据并发送数据的方式给其他订阅者(发布)。许多 Comet 服务器都实现了 pub/sub 模型。

StreamHub Comet Server 中的真实示例:

订阅:我想接收有关 Google 的新闻:

hub.subscribe("/news/google", function(sTopic, oData) { alert("Received news article about Google: " + oData.Article});

发布:我想贡献一些有关 Google 的新闻:

hub.publish("/news/google", "{'Title':'Google Expanding Access To Wave Soon, First Impressions','Article':'According to Google, included in this group of early testers will be some of the businesses using Google Apps. In anticipation of this wider release, ...'}");

订阅主题“/news/google”的任何人都会收到我上面发布的文章 - 这就是 pub/sub 的工作原理。

Comet is a technology for pushing real-time data to a web browser - so the page can continually update. For more details see this page about Comet.

Pub/Sub (or Publish/Subscribe) is not different to Comet, it is a way of telling a Comet server what data you want to receive (Subscribe) and sending data to other subscribers (Publish). Many Comet servers implement the pub/sub model.

Real world examples in StreamHub Comet Server:

Subscribe: I want to receive news about Google:

hub.subscribe("/news/google", function(sTopic, oData) { alert("Received news article about Google: " + oData.Article});

Publish: I want to contribute some news about Google:

hub.publish("/news/google", "{'Title':'Google Expanding Access To Wave Soon, First Impressions','Article':'According to Google, included in this group of early testers will be some of the businesses using Google Apps. In anticipation of this wider release, ...'}");

Anyone subscribed to the topic "/news/google" will receive the article I published above - that's how pub/sub works.

泪之魂 2024-08-10 18:03:02

发布-订阅是一种异步通信方式,可将发布者与订阅者解耦。发布者不是将消息发送给特定的订阅者,而是发布有关某个主题的消息。订阅者订阅该主题。给定主题可以有许多发布者和许多订阅者。

例如,在交易系统中,Google 股票的交易可能会发布在“Trade.GOOG”主题上。然后,订阅者可以通过收听必要的主题来收听特定股票的交易。

Comet 是一种基于 Web 的技术,用于使用长期 HTTP 连接进行服务器推送。

想象一个扑克网站。你的浏览器可以与服务器建立连接,该连接基本上会挂起,直到轮到你做某事(加注、跟注等),而不是每隔几秒点击刷新看看是否需要做某事。轮询是另一个解决方案。

它们的相似之处在于它们本质上都是异步通信的一种方式,但在其他方面是不同的。

Publish-subscribe is a means of asynchronous communication that decouples publishers from subscribers. Rather than addressing messages to particular subscribers, publishers publish messages on a topic. Subscribers subscribe to the topic. A given topic can have many publishers and many subscribers.

For example, in a trading system, trades of Google shares might be published on a topic of "Trade.GOOG". Subscribers could then listen to trades in particular stocks by listening to the requisite topics.

Comet is a Web-based technique for server-push using long-lived HTTP connections.

Imagine a Poker website. Your browser could make a connection to the server, which would essentially hang until it was your turn to do something (raise, call, etc) rather than you hitting refresh every few seconds to see if you need to do something. Polling is another solution to this.

The similarity they both have is that they are essentially a means of asynchronous communication but otherwise are dissimilar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文