The objective of a traditional web application was to serve static documents. To update the content displayed by those web applications a browser refresh was needed. Such an approach falls short of requirements of modern applications of serving dynamic content. It is unacceptable for users to initiate a refresh, therefore, applications need to autonomously pull updates. This is where Web Application Messaging Protocol (WAMP) comes into the picture.
Modern applications are architected as separate small components that simplify development and maintenance. The different components need a way to communicate. There are two commonly used patterns for web application messaging. The first pattern is Publish and Subscribe whereas, the second pattern is Remote Procedure Calls (RPC).
The PubSub topology is comprised of one publisher and many subscribers. The publisher composes messages which are pushed to subscribers. Subscribers have the option of receiving all messages pushed to them or subscribing to specific messages which are referred to as Topics. The PubSub protocol has the advantage of using a broker to separate publishers and subscribers. Therefore either subscribers or publishers do not need knowledge of each other. This simplifies implementation and improves scalability. There are three subscription approaches that can be used. In an architecture that has a broker subscriptions are made to a broker instead of a server. The broker handles message routing. In a brokerless architecture, the server receives topic requests and sends messages to those clients that made a topic request. In the third approach, clients receive all messages from the server and they filter the messages they do not need. This approach has a shortcoming of not being scalable.
RPC enables one program to communicate with another program on a different network while avoiding network complexities. The RPC message protocol consists of a call and a reply message. In this architecture, a client pushes a remote procedure call to a server and the server sends the results of the execution.
An architecture that supports PubSub and RPC would require two servers hosting two technology stacks that may not be compatible. The application building blocks would thereby need to connect to each service thus requiring separate connections for each protocol. Application requirements such as authentication and authorization would require separate APIs thereby increasing application complexity.
Web Application Messaging Protocol (WAMP) was developed as a solution to the problem of integrating PubSub and RPC. The design objectives of WAMP were to provide high performance, safety, and easy implementation. WAMP solves the integration problem by separating communication components. The separation happens through routing messages thereby eliminating the need for components to identify other components. When there is one connection, API and library it is possible for an application to use PubSub and RPC. These will handle all communication between front and back ends.
WAMP is not limited to supporting web applications. It is an appropriate solution for distributed applications. An outstanding advantage of Web Application Messaging Protocol (WAMP) is, it supports separation of components that need to communicate. Direct communication is not required instead a router handles message distribution. Another advantage of WAMP is it is language agnostic therefore it does not limit you to a specific programming language. Other protocols relying on routing make WAMP a complete solution for distributed application messaging. Available protocols available in WAMP are authentication, authorization, subscription, and registration and publication control among others. Because WAMP was designed for deployment on public and private networks it can use SSL/TSL encryption on Websocket or raw protocol. These capabilities make WAMP an excellent choice for IoT solutions.
WAMP messages are created using JSON format, therefore, arguments and results of remote procedures can be serialized as JSON. Other serialization protocols such as CBOR, UBJSON and MessagePack can be used because they can be plugged into WAMP protocol.
The default transport protocol used in WAMP is Websocket. This makes it possible for components to be located anywhere an outgoing HTTP connection can be made. For example components can be run on web browsers and mobile devices. With Websocket transport it is possible to create a persistent two-way connection that enables messages to be truly pushed from the server. Messages do not have HTTP headers and this minimizes overhead as compared to messages that have HTTP headers.
An alternative transport that can be used by WAMP is Rawsocket. WAMP over RawSocket uses binary messages which are different from the messaging approach used in Websocket. RawSocket has advantages over Websocket. One advantage is the implementation of Websocket is easier s there is no need to implement features like HTTP handshakes, masking, and message fragmentation. A second advantage is Rawsocket has a lower overhead which is valuable for running local connections and microcontrollers that have less than 2KB RAM. Rawsocket has its disadvantages too. One disadvantage is TCP connections are not allowed on browsers. To be used on web browser clients’ browser extensions must be installed. Another disadvantage is Rawsocket lacks transport level compression.
WAMP is made up of several components and roles. The PubSub protocol has three roles namely Subscribers and publishers whose communication is through a broker. The RPC protocol to has three roles namely Callers and Callee that communicate through a dealer. A Router takes on the role of either a router or a dealer. In PubSub protocol a client can take the role of a subscriber, publisher, caller or callee. After a client makes a successful connection to a Router a session is created by joining a realm. A realm provides routing and administration features that can be configured to enable authorization and authentication.
This tutorial introduced the limitations of traditional static applications and modern dynamic applications. The problem of communication between different components was introduced. The communication solution offered by the integration of PubSub and RPC into WAMP was discussed. Finally, the protocols available in WAMP were discussed.