Note: the project and this document are hosted here: https://github.com/marianoguerra/pshb-example improvements and corrections are welcome!
welcome, this document contains an example application written in python that will help you play with a pshb (pubsubhubbub from now on) hub and an application that publishes its content to it.
this guide explains how to install a pubsubhubbub server in your computer so you can play with it, normally on a web application you would use a pshb compatible server like:
- official pshb hub on app engine: http://pubsubhubbub.appspot.com/
- superfeedr hub: http://superfeedr.com/
- python >= 2.5 (I'm using 2.6.1)
- git (for the example)
- subversion (to download pshb code)
- bash or similar shell to run the scripts
git clone https://github.com/marianoguerra/pshb-example.gitthe first command will fetch the project from github, the third one will get some libraries needed for the example to run.
note: answer "y" to sammy and "n" to all the other questions that the script does (we don't need those libraries)
now we will start the example application called pleinu twice (so we can test the communication using the hub) and we will start a local pshb hub.
open 3 terminals and run one comment on each one:
google_appengine/dev_appserver.py src/ -p 8000 --datastore_path=/tmp/tubes1this commands asume that you are at the root of the pshb-example folder.
google_appengine/dev_appserver.py src/ -p 8001 --datastore_path=/tmp/tubes2
open a browser tabs pointing to:
click the signup link and create a new user.
I will create one called spongebob, you will have to change the username whenever you see it.
after the signup process click the login button and enter the user and password you just entered.
create a message and click send, the message should appear below.
now go to http://localhost:8000/atom/messages/from/spongebob/
you should see an atom feed with the message you just created.
now that we have a page that generates information we need to publish it on the hub.
open a tab in your browser pointing to http://localhost:8080/ and click on the publish link near the bottom.
if you get an error remove the s from the https protocol in the address bar and refresh.
on the Topic field enter the url to the atom feed we saw before: http://localhost:8000/atom/messages/from/spongebob/
and click Publish, the page wont change, that's ok.
now we need to subscribe one user from the other site (http://localhost:8001/) to the messages sent by our user.
go to http://localhost:8001/ and create another user, I will call it patrick
in the main page of the hub (http://localhost:8080/) click on the subscribe like near the bottom
enter http://localhost:8001/p/notify/patrick/ on the Callback field (change patrick for your username if you used another one) enter http://localhost:8000/atom/messages/from/spongebob/ on the Topic field (change spongebob for your username if you used another one)
click the "Do it" button, the page won't change, that's ok.
Sending a message
Go to http://localhost:8000/ (login if you closed it) and send a message.
Now go to http://localhost:8001/ and refresh the page, you should see the messages published by the user in the other site.
if you get that exception like this:
in log_requestedit the function to look like this:
self.requestline, str(code), str(size))
tools/dev_appserver.py", line 3314, in log_message
AttributeError: DevAppServerRequestHandler instance has no attribute
def log_message(self, format, *args):
"""Redirect log messages through the logging module."""
you will have to set write permissions to the file to save it (chmod u+w dev_appserver.py)
you will have to restart the pshb server: