My favorites | Sign in
Project Home Wiki Issues Source
Search
for
DeveloperGettingStartedGuide  
Guide for developers to get started with PubSubHubbub
Featured
Updated Mar 30, 2011 by luismarianoguerra@gmail.com

Also see:


PubHubSubBub Developer Tutorial

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:

Requirements

  • 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

Installing

	git clone https://github.com/marianoguerra/pshb-example.git
	cd pshb-example
	bash setup.sh

the 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)

Running

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/tubes1
google_appengine/dev_appserver.py src/ -p 8001 --datastore_path=/tmp/tubes2
google_appengine/dev_appserver.py pubsubhubbub/hub/

this commands asume that you are at the root of the pshb-example folder.

Playing

open a browser tabs pointing to:

http://localhost:8000/

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.

Publishing

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.

Subscribing

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.

Note

to make it work and avoid an exception I had to add a return statement at the beginning of the log_message function at google_appengine/google/appengine/tools/dev_appserver.py

if you get that exception like this:

in log_request
    self.requestline, str(code), str(size))
  File "/home/asd/pubsubhubbub/pshb/google_appengine/google/appengine/
tools/dev_appserver.py", line 3314, in log_message
    if self.channel_poll_path_re.match(self.path):
AttributeError: DevAppServerRequestHandler instance has no attribute
'path'

edit the function to look like this:

def log_message(self, format, *args):
  """Redirect log messages through the logging module."""
  return
  if self.channel_poll_path_re.match(self.path):
    logging.debug(format, *args)
  else:
    logging.info(format, *args)

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:

google_appengine/dev_appserver.py pubsubhubbub/hub/

Comment by ramkuma...@gmail.com, Oct 4, 2009

Just a note: Before one can see the tasks in the feed-pulls, one has to run the mappings task to accept the subscription of a topic to the hub.

Comment by dougvand...@gmail.com, Oct 9, 2009

Was able to get the demo up, but could not create content. Getting error: 127.0.0.1 - - [09/Oct/2009 13:14:50] "GET /files/json.js HTTP/1.1" 404 -

Comment by adam.oakman, Nov 21, 2009

Hmm when trying to start ihasfriendz I get: python main.py

File "main.py", line 32
class User(object):
^
SyntaxError?: invalid syntax

Seems to be the decorators: @tubes.JsonClass?()

Did I miss a prereq or something?

Comment by ramon.zi...@gmail.com, Dec 2, 2009

Hi adam.oakman

I think that your problem is the version of python. What python version your use to run main.py?

Look that version to run pubsub is different to run main.py. In first case is python '2.5', in second is '2.6'. I believe that if you use this correct version to each situation, main.py will run fine.

Comment by pjkeane, Jan 24, 2010

There is a problem getting this demo to run under python 2.6. The error occurs when manually running the event-delivery task queue. The error:

File "/home/pkeane/Desktop/google_appengine/pubsubhubbub/hub/main.py", line 301, in sha1_hmac
return hmac.new(secret, data, hashlib.sha1).hexdigest()
File "/usr/lib/python2.6/hmac.py", line 133, in new
return HMAC(key, msg, digestmod)
File "/usr/lib/python2.6/hmac.py", line 72, in init
self.outer.update(key.translate(trans_5C))

TypeError?: character mapping must return integer, None or unicode

Is due to this "bug:" http://bugs.python.org/issue5285

Comment by vgri...@gmail.com, Mar 2, 2010

sequence of actions starting from "components used" was different to me:

  1. register subscriber
  2. run mapping queue
  3. register publisher
  4. (run as many times as needed) create content through ihazfriends
  5. (run feed-pull and event-delivery queues
  6. view http://localhost:8081/new-notices/

I hope that helps to smb :)

Comment by ravi.rg....@gmail.com, Apr 2, 2010

When we use GAE 1.2.4 the hub won't start. It needs atleast GAE 1.2.8 to start the hub. It will be helpful if you can update the guide.

Comment by Jen...@gmail.com, Apr 13, 2010

GAE python toolkit must be run with python 2.5. I tried python 2.6 to go through the tutorial process. It gave error messages in some steps.

Comment by terror...@gmail.com, Apr 14, 2010

Traceback (most recent call last):

File "main.py", line 8, in <module>
import simplejson as json
ImportError?: No module named simplejson

Comment by jwk2...@gmail.com, Apr 14, 2010

I ran through this demo successfully on Ubuntu 9.10 using the default installed python (2.6). But it requires latest version of GAE, as such:

wget http://googleappengine.googlecode.com/files/google_appengine_1.3.2.zip unzip google_appengine_1.3.2.zip

Then execute the hub service: python google_appengine/dev_appserver.py pubsubhubbub/hub/

Comment by rawfunkc...@gmail.com, Jun 10, 2010

Without coming across as a total moron, does this get installed to my local test server, or installed to my web server?

Any help appreciated :)

Comment by g.h.ba...@gmail.com, Jul 26, 2010

Using: python2.5 google_appengine/dev_appserver.py pubsubhubbub/hub/

It dies due pubsubhubbub/hub/dos.py. It tries to access offset_multi which is not part of the module 'memcache'.

Comment by apache.s...@gmail.com, Jul 31, 2010

Worked for me. Use Python 2.5 for demo. Deploying in production.

Comment by apache.s...@gmail.com, Aug 1, 2010

Is this app, with its default configuration, polling for feeds that do not ping the hub, e.g. regular feeds, non-pubsubhub aware?

Comment by fingol...@gmail.com, Sep 14, 2010

I have one little problem, when running the "delivery" queue, it just wont work, I keep pressing the "run" button but it does nothing <_>

Comment by rferol...@gmail.com, Sep 24, 2010

I tried in Ubuntu 10.4 server mode with python 2.6 and it run without a problem. I just have to change from localhost to the IP address of Ubuntu since the server is running in VMWARE Fusion. Great example and tutorial.

Comment by Tim.Pi...@gmail.com, Oct 18, 2010

Gives

File "/home/timp/pshb/google_appengine/google/appengine/tools/dev_appserver.py", line 3280, in log_message
if self.channel_poll_path_re.match(self.path):
AttributeError?: DevAppServerRequestHandler? instance has no attribute 'path'

on Debian 10.04, Python 2.6, App Engine 1.3.8

Comment by Tim.Pi...@gmail.com, Oct 18, 2010

Neither downgrading python to 2.5 nor using app engine trunk fixes. Erratic behaviour with no error handling. Has put me off.

Comment by brian.gu...@gmail.com, Feb 6, 2011

got it running with google_appengine_1.4.1.zip w/ python 2.6 on ubuntu. don't use a secret key with the example, because it will expose a bug and not push events.

Comment by nik...@gmail.com, Mar 1, 2011

you might want to update the URL link to suprfeedr 'getting started' article, it is at:

http://blog.superfeedr.com/pubsubhubbub/API/getting-started-with-pubsubhubbub/

Comment by mpe...@gmail.com, Mar 24, 2011

Does anyone knows exactly how should i get started if i want to create custom services on the server? Actually i want to create a custom interface for the service, so i need to be able to know how to subscribe and when a new feed comes to extract it and display it somewhere else! It would be really helpful if someone can point out those, instead of searching the whole code. Thank you very much!!

Comment by pavan...@gmail.com, Apr 20, 2011

I have followed the instructions and find that there are quite a few .js files missing from src/js directory..

Comment by mkw...@google.com, May 19, 2011

Not sure if anyone else ran into this, but if I log into localhost:8000 and localhost:8001 using 2 users in 2 separate tabs in a single browser instance (Chrome in this case), it causes the web app to fail (and not be able to send messages). Using incognito window for one worked, so it's probably just a cookie issue. Figures I'd make a note in case anyone else but me gets confused on it.

Comment by max.bea...@reputation.com, May 23, 2011

After installing and setting up everything, I'm still missing req.js which I think is preventing me from logging in. Anyone have a fix?

Comment by xinec...@gmail.com, Jun 15, 2011

If the file req.js is missing and you have the jQuery library, you can substitute the command to its functions with some jQuery functions. req is called from the file ui.js:

line 34 is req.get(path + offset + "/" + limit + "/", ui.onLoadStreamOk, ui.errorCb("couldn't load stream")); it can be substituted with
jQuery.ajax({
url: path + offset + "/" + limit + "/", global: false, type: "GET", success: ui.onLoadStreamOk, error: ui.errorCb("couldn't load stream"),
});

line 66 req.post("/a/login/", {"user": user, "password": password}, ui.onLoginOk, ui.onLoginError); it can be substituted with
jQuery.ajax({
url: "/a/login/", global: false, type: "POST", contentType: "application/json", data: '{"user": "'+ user +'", "password":"'+ password+'"}', dataType: "json", async:false, success: ui.onLoginOk, error: ui.onLoginError,
});
and line 116 req.create("/a/message/", model.message(text, user), ui.onSendMessageOk, ui.errorCb("couldn't save message")); it can be replaced with
jQuery.ajax({
url: "/a/message/", global: false, type: "POST", contentType: "application/json", data: JSON.stringify(model.message(text, user)), async:false, success: ui.onSendMessageOk, error: ui.errorCb("couldn't save message"),
});

At the end, in src/templates/index.html you can remove line 61 <script src="/static/js/req.js"></script>


Sign in to add a comment
Powered by Google Project Hosting