Search code examples
javajettycometdwrpublish-subscribe

comet vs pubsub..?


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


Solution

  • 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.