Sunday, March 15, 2015

WAMP Publisher / Subscriber Example

One of the topics covered in our homework this week was setting up an asynchronous WAMP publisher / subscriber example using Python. WAMP stands for "Web Application Messaging Protocol", which is a sub-protocol which leverages Websockets (which in turn leverage HTTP) to set up asynchronous communication models. The Python implementation uses AutobahnPython (WAMP implemented on the Twisted network library) to do this. The example code in the book and the procedures used to do this are unfortunately out of date, so the code needed to be modified to get this to work. I had to modify each code sample to clean up some spelling / syntax, and add a "main" function at the bottom to start an ApplicationRunner using the ApplicationSession defined above. Code is available here.

Setup Instructions

  1. Install Python 2.7 with Virtualenv extension
  2. 'virtualenv wamp' to create a new blank "wamp" Virtualenv container
  3. 'source wamp/bin/activate' to turn on Virtualenv container
  4. 'pip install crossbar' to install Crossbar.io WAMP router, will get AutobahnPython as a dependancy
  5. Create a new blank Crossbar.io server to use as a WAMP router
    1. 'mkdir server'
    2. 'cd server'
    3. 'crossbar init'

Usage Instructions

  1. Start the WAMP router
    1. 'cd server'
    2. 'crossbar start'
  2. Start the Subscriber (./subscriberApp.py)
  3. Start the Publisher (./publisherApp.py)

What's Going On Here

When the server is started, it is accepting all new topics published to 'realm1' without any authentication. When the subscriber joins, it is telling the server "please send me any new updates to com.example.test-topic". When the publisher joins, it starts an infinate loop of taking the current time and updating the topic 'com.example.test-topic' with that value. The server then sends those updates to the subscriber client, which prints them out.

No comments:

Post a Comment