WAMP Examples

NOTE that for all examples you will need to run a router. We develop Crossbar.io and there are other routers available as well. We include a working Crossbar.io configuration in the examples/router/ subdirectory as well as instructions on how to run it.

Overview of Examples

The examples are organized between asyncio and Twisted at the top-level, with similarly-named examples demonstrating the same functionality with the respective framework.

Each example typically includes four things:

  • frontend.py: the Caller or Subscriber, in Python
  • backend.py: the Callee or Publisher, in Python
  • frontend.js: JavaScript version of the frontend
  • backend.js: JavaScript version of the backend
  • *.html: boilerplate so a browser can run the JavaScript

So for each example, you start one backend and one frontend component (your choice). You can usually start multiple frontend components with no problem, but will get errors if you start two backends trying to register at the same procedure URI (for example).

Still, you are encouraged to try playing with mixing and matching the frontend and backend components, starting multiple front-ends, etc. to explore Crossbar and Autobahn’s behavior. Often the different examples use similar URIs for procedures and published events, so you can even try mixing between the examples.

The provided Crossbar.io configuration will run a Web server that you can visit at http://localhost:8080 and includes links to the frontend/backend HTML for the javascript versions. Usually these just use console.log() so you’ll have to open up the JavaScript console in your browser to see it working.

Automatically Run All Examples

There is a script (./examples/run-all-examples.py) which runs all the WAMP examples for 5 seconds each, this asciicast shows you how (see comments for how to run it yourself):

Publish & Subscribe (PubSub)

Remote Procedure Calls (RPC)

  • Time Service Twisted - asyncio - A trivial time service - demonstrates basic remote procedure feature.
  • Slow Square Twisted - asyncio - Demonstrates procedures which return promises and return asynchronously.
  • Arguments Twisted - asyncio - Demonstrates all variants of call arguments.
  • Complex Result Twisted - asyncio - Demonstrates complex call results (call results with more than one positional or keyword results).
  • Errors Twisted - asyncio - Demonstrates error raising and catching over remote procedures.
  • Progressive Results Twisted - asyncio - Demonstrates calling remote procedures that produce progressive results.
  • Options Twisted - asyncio - Using options with RPC.

I’m Confused, Just Tell Me What To Run

If all that is too many options to consider, you want to do this:

  1. Open 3 terminals
  2. In terminal 1, setup and run a local Crossbar in the root of your Autobahn checkout.
  3. In terminals 2 and 3, go to the root of your Autobahn checkout and activate the virtualenv from step 2 (source venv-autobahn/bin/activate)
  4. In terminal 2 run python ./examples/twisted/wamp/rpc/arguments/backend.py
  5. In terminal 3 run python ./examples/twisted/wamp/rpc/arguments/frontend.py

The above procedure is gone over in this this asciicast:

Reactive Manifesto: We are reactive banner