Web Application Messaging Protocol Explained

WAMP is a WebSocket subprotocol registered at IANA,[1] specified[2] to offer routed RPC and PubSub. Its design goal[3] is to provide an open standard for soft, real-time message exchange between application components and ease the creation of loosely coupled architectures based on microservices. Because of this, it is a suitable enterprise service bus (ESB),[4] fit for developing responsive web applications or coordinating multiple connected IoT devices.[5]

Characteristics

Structure

WAMP requires[6] a reliable, ordered, full-duplex message channel as a transport layer, and by default uses Websocket. However, implementations can use other transports matching these characteristics and communicate with WAMP over e.g. raw sockets,[7] Unix sockets, or HTTP long poll.

Message serialization assumes[8] integers, strings and ordered sequence types are available, and defaults to JSON as the most common format offering these. Implementations often provide MessagePack as a faster alternative to JSON at the cost of an additional dependency.[9]

Workflow

WAMP is architectured around client–client communications with a central software, the router, dispatching messages between them. The typical data exchange workflow is:[10]

The clients send these messages using the two high-level primitives that are RPC and PUB/SUB, doing four core interactions:

This can have subtle variations depending on the underlying transport.[11] However, implementation details are hidden to the end-user who only programs with the two high-level primitives that are RPC and PubSub.

Security

As WAMP uses Websocket, connections can be wrapped in TLS for encryption. Even when full confidentiality is not established, several mechanisms are implemented to isolate components and avoid man-in-the-middle attacks. Default implementations ensure that trying to register an already registered procedure will fail.

Routers can define realms as administrative domains, and clients must specify which realm they want to join upon connection. Once joined, the realm will act as a namespace, preventing clients connected to a realm from using IDs defined in another for RPC and PubSub. Realms also have permissions attached and can limit the clients to one subset of the REGISTER/CALL/PubSub actions available.

Some realms can only be joined by authenticated clients, using various authentication methods such as using TLS certificate, cookies or a simple ticket.

Routed RPCs

Unlike with traditional RPCs, which are addressed directly from a caller to the entity offering the procedure (typically a server backend) and are strictly unidirectional (client-to-server), RPCs in WAMP are routed by a middleware and work bidirectionally.

Registration of RPCs is with the WAMP router, and calls to procedures are similarly issued to the WAMP router. This means first of all that a client can issue all RPCs via the single connection to the WAMP router, and does not need to have any knowledge what client is currently offering the procedure, where that client resides or how to address it. This can indeed change between calls, opening up the possibility for advanced features such as load-balancing or fail-over for procedure calls.

It additionally means that all WAMP clients are equal in that they can offer procedures for calling. This avoids the traditional distinction between clients and server backends, and allows architectures where browser clients call procedures on other browser clients, with an API that feels like peer to peer communication.

However, even with multi-tiers architectures, the router is still a single point of failure. For this reason, some router implementation roadmaps include clustering features.[12]

Implementations

Clients

As WAMP main targets are Web applications and the Internet of Things, the first client implementations are in languages well established in these industries (only WAMP v2 clients listed):

Client libraryLanguage
AngularWAMPJavaScript for the AngularJS framework
AutobahnCppC++ 11
wamplvLabVIEW (G)
AutobahnJSJavaScript (browser and Node.js)
AutobahnPythonPython
wampyPython
Net::WAMPPerl
backbone.WAMPJavaScript for the Backbone.js library
CppWAMPC++ 11
ErwaErlang
JawampaJava
[| [https://github.com/KSDaemon/Loowy Loowy]| Lua|- | MDWamp| Objective-C|-| Minion| PHP|-| rx.wamp| JavaScript for the React library|-| Thruway| PHP|-| WAMP POCO| C++|-| wampcc| C++|-| WampSharp| C#|-| Wampy.js| JavaScript (browser only)|-| nexus| Go|}

The minimum requirements to build a WAMP client are the abilities to use sockets and to serialise to JSON. Thus, many modern languages already fulfill these requirements with their standard library. Additional features which would add dependencies, such as TLS encryptions or MessagePack serialization, are optional.

However, the persistent nature of WebSocket connections requires the use of non-blocking libraries and asynchronous APIs. In languages with one official mechanism such as JavaScript, Erlang or Go, this is not an issue. But for languages with several competing solutions for asynchronous programming, such as Python or PHP, it forces the client author to commit to a specific part of the ecosystem.

For the same reason, integrating legacy projects can also require work. As an example, most popular Web Python frameworks are using WSGI, a synchronous API, and running a WAMP client inside a WSGI worker needs manual adapters such as crochet.

Routers

While routers can technically be embedded directly into the application code and some client libraries also provide a router, this architecture is discouraged by the specification.[13]

Since the router is a moving part, it is best used as a swappable black box just like one would consider Apache or Nginx for HTTP:

RouterLanguage
Bondy Erlang
Crossbar.io Python (CPython and PyPy)
ErwaErlang
wampccC++
JawampaJava
ThruwayPHP
wamp.rtJavaScript (Node.js only)
WampSharpC#
WiolaLua
Nightlife-RabbitJavaScript (Node.js only)
nexusGo

Tavendo, the company from which originated the protocol, is also the author of Crossbar.io, which promotes itself as the de facto router implementation.[14] As they are promoting microservice-based architectures, Crossbar.io embeds a service manager for hosting and monitoring WAMP app components, a static file Web server, and a WSGI container. Being written with the Twisted library, it is one of the implementations that can be set up in production without a proxy, aiming to replace stacks such as Nginx associated with Supervisor and Gunicorn.

Use cases

Being a WebSocket sub-protocol, WAMP fits naturally anywhere one would use raw web sockets, as a way to synchronize clients such as Web browsers, push notifications to them and allow soft real-time collaboration between users.[15] It has also the same limitations, requiring client support, which is missing for Internet Explorer versions older than 10.[16] This is mitigated by the existence of polyfills[17] using more portable technologies such as Flash or the use of HTTP Longpoll as a fallback. In that sense, WAMP is a competitor to Meteor's DDP.

WAMP also targets the IoT, where it is used in the same way as MQTT[18] as a light and efficient medium to orchestrate clusters of connected objects. The implementations in various languages make it suitable to control and monitor small devices such as the Raspberry Pi (in Python) or the Tessel[19] (in JavaScript).

And last but not least, WAMP can act as an enterprise service bus, serving as the link between microservices like one would do with CORBA, ZeroMQ, Apache Thrift, SOAP or AMQP.

Evolution

WAMP is currently in version 2[20] which introduced routed RPC. As of now, all routers are compatible with version 2. Some clients remain unported: Wamp.io, AutobahnAndroid, and cljWAMP.

The version 2 of the specification is divided into two parts: the basic profile, including the router RPC and Pub/Sub, and the advanced profile, featuring trust levels, URI pattern matching, and client listing. The basic profile is considered stable and is what current libraries are implementing while the advanced profile is still in evolution.

Comparison

The WAMP website claims[21] the following selling points for the technology:

  • Native PubSub: supports Publish & Subscribe out of the box (no extension required).
  • RPC: supports Remote Procedure Calls out of the box (no extension required).
  • Routed RPC: supports routed (not only point-to-point) Remote Procedure Calls.
  • Web native: runs natively on the Web (without tunneling or bridging).
  • Cross Language: works on and between different programming languages and run-times.
  • Open Standard: Is an open, official specification implemented by different vendors.

On the other hand, WAMP does not try to achieve some goals of other protocols:

  • Full object passing like CORBA.
  • Data synchronization like DDP.
  • Peer-to-peer communication like ZeroMQ.
  • Multi-media streaming like WebRTC.
  • Large file transfer like HTTP.

Nevertheless, numerous protocols share some characteristics with WAMP:

TechnologyPubSubRPCRouted RPCWeb nativeCross LanguageOpen Standard
WAMP
AJAX
AMQP
Apache Thrift
Capn'n'Proto
Comet
OMG DDS
D-Bus
CORBA
DCOM
Java JMS
Java RMI
JSON-RPC
MQTT
REST
SOAP
Socket.io
SockJS
STOMP
XML-RPC
XMPP
ZeroMQ
DDP[22]

Although, it is important to note that while DDP does Pub/Sub under the hood to synchronize data sets, it does not expose PubSub primitives. It also is an open specification with several implementations, but not registered as a standard.

References

Notes and References

  1. https://www.iana.org/assignments/websocket/websocket.xml IANA protocols listing page
  2. https://github.com/tavendo/WAMP/blob/master/spec/basic.md WAMP basic profile specifications
  3. Web site: Using WAMP you can build distributed systems out of application components which are loosely coupled and communicate in (soft) real-time..
  4. http://www.slideshare.net/KSDaemon/wamp-en-exported A few words about WAMP
  5. Book: In this chapter [...] you will learn about the Web Application Messaging Protocol [...] which provide tools and services for developing IoT solutions]. 9780996025515. Bahga. Arshdeep. Madisetti. Vijay. 9 August 2014.
  6. Web site: Crossbar.io router transport . 2015-01-12 . 2015-01-12 . https://web.archive.org/web/20150112101645/http://crossbar.io/docs/Router-Transports/ . dead .
  7. Web site: WAMP can run over Raw transports instead of WebSocket. Each message is prefixed with a uint32 (big endian) that provides the (serialized) length of the following WAMP message.. .
  8. https://github.com/tavendo/WAMP/blob/master/spec/basic.md#serializations WAMP serialization
  9. Web site: Wampy default serializer is JSON, but it also supports msgpack as a serializer, but you need to include msgpack.js as dependency.
  10. https://github.com/tavendo/WAMP/raw/master/spec/figure/sessions2.png WAMP internals bird view diagram
  11. Web site: The Long-Poll Transport is able to transmit a WAMP session over plain old HTTP 1.0/1.1. This is realized by the Client issuing HTTP/POSTs requests, one for sending, and one for receiving. .
  12. Web site: Crossbar node architecture . 2015-04-20 . 2015-01-12 . https://web.archive.org/web/20150112133407/http://crossbar.io/docs/Architecture/ . dead .
  13. Web site: Brokers and Dealers are responsible for generic call and event routing and do not run application code.. .
  14. Web site: Crossbar.io is the name of the most full-featured router. 26 December 2014 .
  15. https://github.com/voryx/angular-wamp WAMP and AngularJS
  16. Web site: Can is use websockets ?.
  17. https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills Web socket polyfills
  18. Web site: Moreover, we compared WAMP with other registered WebSocket subprotocols (MBWS, SOAP and STOMP) in terms of the related features; and with other potential protocols (CoAP and MQTT), in terms of the related practical deployments.. 2015-01-12. 2016-05-13. https://web.archive.org/web/20160513073741/https://into.aalto.fi/download/attachments/12324178/Huang_Fuguo_thesis_2.pdf. dead.
  19. https://www.youtube.com/watch?v=WY7KzrRm8XY Tessel alarm app with Crossbar.io
  20. https://wamp-proto.org/spec.html WAMP 2 specification menu
  21. https://wamp-proto.org/comparison.html WAMP compared
  22. https://github.com/meteor/meteor/blob/devel/packages/ddp/DDP.md DDP specs