We love designing and developing websites, but what really drives us is solving problems and cultivating strong relationships with our clients
Real time applications with Django, XMPP and StropheJS
By : Javed
TL;DR:
- django-pubsub allows you to create Twitter like real-time updates for your models with Admin like ease.
- Demo at http://chat.agiliq.com/pubsub/
- Code at https://github.com/agiliq/django-pubsub
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
Comments
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!
Reactions
Build real time xmpp applications with ease. http://agiliq.com/blog/2010/12/real-time-applications-with-django-xmpp-and-stroph/
RT@agiliqdotcom: Build real time xmpp applications with ease. http://agiliq.com/blog/2010/12/real-time-applications-with-django-xmpp-and-stroph/
RT@agiliqdotcom: Build real time xmpp applications with ease. http://agiliq.com/blog/2010/12/real-time-applications-with-django-xmpp-and-stroph/
RT@agiliqdotcom: Build real time xmpp applications with ease. http://agiliq.com/blog/2010/12/real-time-applications-with-django-xmpp-and-stroph/
RT@agiliqdotcom: Build real time xmpp applications with ease. http://agiliq.com/blog/2010/12/real-time-applications-with-django-xmpp-and-stroph/
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog: http://bit.ly/f6Wqdx
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://goo.gl/fb/8Fmz4
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.
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?
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://j.mp/hjEslO
RT@joshva: Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://j.mp/hjEslO
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog: http://bit.ly/fhakNb
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog: Comments http://goo.gl/fb/6VoH2
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://goo.gl/fb/u5TTR
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://goo.gl/fb/sV5NO
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://goo.gl/fb/iXGtf
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog - http://bit.ly/fFseMb - [Hacker News Top]
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog: Comments http://digfoc.us/eFy4j6
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog: Comments http://bit.ly/ftQjhF
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://goo.gl/fb/gDYd9
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://goo.gl/fb/v5Lys
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://bit.ly/hbUJxe (http://bit.ly/gaUOMJ)
Real time applications with Django, XMPP and StropheJS http://bit.ly/dMAFxb
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://icio.us/M9hosn
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://dlvr.it/C6829
RT@HackerNewsYC: Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://ow.ly/1rYGwj
Real time applications with Django, XMPP and StropheJS http://ping.fm/2HvM1
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://bit.ly/fyvYSc
Real time applications with Django, XMPP and StropheJS - The Agiliq Blog http://t.co/SrYRBVd
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
@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
- Test Driven Development in Python
- Deploying Django apps on Heroku
- Developing android applications from command line
- Deploy Django App in 5 Easy Steps
- Project Management Tools for Start-Ups
- Generating a pdf from an image using PIL and django
- Dynamically attaching SITE_ID to Django Caching
- Screencast: How to deploy Django on Heroku
- Deploying Django apps on Heroku
- How to use pep8.py to write better Django code
- rails
- django
- linkroundup
- django opinion
- opinion
- business
- API
- appengine
- python
- satire
- startup
- Uncategorized
- marketing
- personal
- rambling
- search
- interviews
- seo-interviews
- 5startupideas
- ideas
- seo
- tips
- forms
- paypal
- utilities
- datetime
- web2.0
- Amazon
- algorithms
- presentations
- products
- pinax
- satchmo
- ecommerce
- microsoft
- yahoo
- book
- tutorial
- models
- aggreagtion
- meta
- India
- apps
- about
- CSS
- Design
- wordpress
- test slug
- vim
- urls
- reviews
- javascript
- xmpp
- emacs
- Typography
- Grid Theory
- Color Theory
- iphone
- android
- titanium
- mobile applications
- CSS3
- Browser Compatibility
- mobile
- jobs
- lamson
- django setup
- files
- upload
- jsTree
- hierarchical view
- web page
- Treeview
- coffeescript
- request
- response
- South
- django south
- django migration
- --fake
- screencasts
- django caching
- SITE_ID prefix
- review
- code hosting
- comparison
- unfuddle
- fogbugz
- assembla
- github
- project management
- ticketing system
- gunicorn
- deploy
- nginx
- ubuntu
- vps
- android terminal
- terminal
- programming
- TDD
- Test Driven
- Development
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- October 2011
- September 2011
- July 2011
- June 2011
- April 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- June 2010
- April 2010
- March 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- April 2009
- March 2009
- February 2009
- November 2008
- October 2008
- June 2008
- May 2008
- April 2008
Was disappointed to find that this article actually says nothing about StropheJS.