Search code examples
wampautobahncrossbar

WAMP RPC functions with the same name on different devices


I have a program that registers an RPC function, ex. com.myapp.foo. I then run this program on several independent devices, all connected to the same router.

When I start up the second device, it gets an error, because the RPC function has already been registered (wamp.error.procedure_already_exists).

This makes sense, since the router needs a unique name in order to route procedure calls properly. But in my case,

My first thought was that each device should generate a unique procedure name (com.myapp.device4.foo).

  • But, then how does a program generate a unique name (is there something more sophisticated than looping until a unique name was found)?
  • Also, more importantly, how would a caller discover the name of the procedure that is associated with a particular node? For example, a caller will want to find all devices that are up, and then call com.myapp.foo on each of them.

I'm working in python/asyncio and javascript, both using autobahn on the crossbar.io server.


Solution

  • Generating a unique name:

    • Use a data point unique to the device, e.g. its MAC or a serial number.
    • Create a random string long enough that collisions within your application are practically excluded.

    The first variant has the advantage that procedure URLs are persistent and easy to correlate with the device.

    Discovering registered procedures:

    If your clients have permissons to access it, the WAMP meta API allows querying for existing procedures - see http://crossbar.io/docs/Registration-Meta-Events-and-Procedures/

    If your URLs contain the the MAC/device serial/other unique info to the device, then that's all you need to know which devices are currently up.