Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

comet vs pubsub..?

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

like image 732
cometta Avatar asked Sep 01 '09 13:09

cometta


2 Answers

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.

like image 67
DLauer Avatar answered Sep 18 '22 17:09

DLauer


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.

like image 22
cletus Avatar answered Sep 20 '22 17:09

cletus