Javed
Comments
Reactions

Real time applications with Django, XMPP and StropheJS

By : Javed Khan

TL;DR:

Introduction:

PubSub is a XMPP extension which allows publishing and subscribing to events. This is useful when you instantly want to notify many clients about something interesting happening on your server.

Quoting the authors of PubSub specs:

The protocol enables XMPP entities to create nodes (topics) at a
pubsub service and publish information at those nodes; an event
notification (with or without payload) is then broadcasted to all
entities that have subscribed to the node. Pubsub therefore
adheres to the classic Observer design pattern and can serve as
the foundation for a wide variety of applications, including news
feeds, content syndication, rich presence, geolocation, workflow
systems, network management systems, and any other application
that requires event notifications.

To understand this better, think of newspapers as publishers and the people who subscribe to the newspapers as subscribers. Getting your daily newspaper is similar to checking your RSS feeds because you only get information at regular intervals. (Of course you could keep buying newspapers every 'x' hours, i.e. keep refreshing your RSS reader so often). This is as inefficient as it sounds. For instance, you never know if a newspaper actually has new stuff, you need to buy and read it before you realize there's nothing new. And there will be always be a delay (unless you are really lucky) between the time something happens and you read it in the your 'n'th newspaper of the day.

PubSub solves this problem by having a system where subscribers subscribe to nodes and the publisher notifies its subscribers when something happens. Nodes are like TV channels, so you only subscribe to the channels you are interested in.

How it can be useful to you:

In addition to the points mentioned in the quote, pubSub can be used in your project to send instant notifications, maintain the same state across multiple sessions, or monitor live activity.

Introducing django-pubsub:

django-pubsub allows you write PubSub enabled applications easily.

This demo using django-pubsub shows how to use the module. The stack used in the demo is:

  • fcgi
  • nginx
  • ejabberd with mod_http_bind and mod_pubsub

You can register a model with the pubsub app and all registered models will automatically send out notification (with the payload) on save to the default node.

Then you can use the PubSub client provided in media to subscribe and receive events from the registered models.

The default payload includes an XML serialized instance of the model. You can use jquery to extract required fields from the payload.

You can also directly use pubsub.publish to publish any item to any node. An example is provided in the demo included with the app.

How it works:

Since XMPP and HTTP speak different languages, you need some kind of a bridge to connect these two. This can be achieved using BOSH.

The BOSH bridge is provided by ejabberd's mod_http_bind module. (You can also use Punjab for this purpose)

If you are using mod_http_bind, you will also need to setup appropriate url forwarding using nginx because mod_http_bind listens on the port 5280 and will not be able to communicate with the client on port 8080.

Strophe will use the BOSH url to talk to ejabberd. Our PubSub client which is written using Strophe will then be able to subscribe and receive notifications from the server.

On the server side, the pubsub app uses xmpppy to send out the correct Iq stanzas on save or publish. The client will receive these stanzas on subscribing to the appropriate node.

Conclusion:

If your app needs real-time updates, push notifications, and scalable infrastructure, you can make use of XMPP and Strophejs.

References:

ejabberd's blog post on related topic:

http://www.process-one.net/en/blogs/article/introducing_the_xmpp_application_server

a similar project using comet, orbit and twisted instead of xmpp:

http://www.clemesha.org/blog/realtime-web-apps-python-django-orbited-twisted


Related Posts


Can we help you build amazing apps? Contact us today.

Comments

Ben Davis 3rd Jan., 2011

Was disappointed to find that this article actually says nothing about StropheJS.

commmenttor
rosetta stone

Rosetta Stone is proprietary language-learning software produced by Rosetta Stone;Ltd. Its title and its logo refer to the Rosetta Stone , an artifact inscribed in multiple languages that helped Jean-Fran?ois Champollion to decipher Egyptian hieroglyphics.
The Rosetta Stone software uses a combination of images, text, and sound, with difficulty levels increasing as the student progresses, in order to teach various vocabulary terms and grammatical functions intuitively, without drills or translation. They call this the Dynamic Immersion method;. The goal is to teach languages the way first languages are learned.Now,the Rosetta Stone;Ltd have several kinds of the Rosetta Stone language on sale,such as Rosetta Stone Spanish,Rosetta Stone German and Rosetta Stone Italian, these Rosetta Stone Languages are very popular now!

commmenttor

Reactions

djangostories

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog: http://bit.ly/f6Wqdx

commmenttor
myikegami_bot

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://goo.gl/fb/8Fmz4

commmenttor
japherwocky

I think one of the easiest tools to work with is http://tornadoweb.org/ - hacking apart their chat demo will get you most of the way there.

commmenttor
shorbaji

Interesting work that looks promising.In general though, is it just me or are we yet to see an API/library/protocol that makes it 'simple' to add real time capabilities to an app?

commmenttor
joshva

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://j.mp/hjEslO

commmenttor
Lius_Hoo89

RT@joshva: Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://j.mp/hjEslO

commmenttor
hnfirehose

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog: http://bit.ly/fhakNb

commmenttor
bartezzini

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog: Comments http://goo.gl/fb/6VoH2

commmenttor
jpaynerss

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://goo.gl/fb/u5TTR

commmenttor
top_technology

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://goo.gl/fb/sV5NO

commmenttor
stevesandersonf

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://goo.gl/fb/iXGtf

commmenttor
newsbloom4

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog - http://bit.ly/fFseMb - [Hacker News Top]

commmenttor
bundleOfThought

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog: Comments http://digfoc.us/eFy4j6

commmenttor
pokkrap

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog: Comments http://bit.ly/ftQjhF

commmenttor
HackerNewsYC

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://goo.gl/fb/gDYd9

commmenttor
mstache_news

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://goo.gl/fb/v5Lys

commmenttor
newsyc20

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://bit.ly/hbUJxe (http://bit.ly/gaUOMJ)

commmenttor
nicolaiarocci

Real time applications with Django, XMPP and StropheJS http://bit.ly/dMAFxb

commmenttor
jonmc12

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://icio.us/M9hosn

commmenttor
solydzajs

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://dlvr.it/C6829

commmenttor
pyweekly

RT@HackerNewsYC: Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://ow.ly/1rYGwj

commmenttor
seyhunak

Real time applications with Django, XMPP and StropheJS http://ping.fm/2HvM1

commmenttor
zaherg

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://bit.ly/fyvYSc

commmenttor
tbillenstein

Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://t.co/SrYRBVd

commmenttor
tuxcanfly

RT@clemesha:@tuxcanfly Cool post: http://is.gd/jC3SY. I also built TheWikiGame.com w/ same tech. Wanna chat about this stuff, let me know. /cc@shabda

commmenttor
clemesha

@tuxcanfly Cool post: http://is.gd/jC3SY. I also built TheWikiGame.com w/ same tech. Wanna chat about this stuff, let me know. /cc@shabda

commmenttor
abrdev

Real time applications with Django, XMPP and StropheJS http://me.lt/7bte

commmenttor
Post a comment Name :

Email :

Your site url:

Comment :

© Agiliq, 2009-2012