When writing your own programme(s) using WAMP, they have to be connected to a WAMP router to be able to communicate with each other. There is a whole bunch of implementations you could use for running a router. In this article I will describe how to set up a local Crossbar.io router.
Why a Local WAMP Router
Web Application Messaging Protocol (WAMP) is a protocol which could be used by many (micro-)services to communicate in a network. The programming languages used by the (micro-)services do not matter and they also do not have to know the address of each other. This means that they could be run anywhere as long as they are connected to the router, they only tell the router where they could be found. Therefore, the router is an integral part of a network using WAMP.
Crossbar.io runs a demo instance of its router which could be accessed by anyone. This sounds easy but involves some setup of your internet connection. The easier way would be setting up your own local router.
In addition, you could use it for your own development when developing with others: When starting to code your own service from scratch while being connected to a remote router, others will probably not be able to access a stable version of your microservice. Therefore, you could run a simple mock-up for them remotely and develop the proper microservice locally.
Setting Up a Local WAMP Router
If your OS is Windows, you should install Make for Windows. It enables you to run the commands in the Makefile. Do not forget to set the bin folder in the environment variables of Windows. If you do not want to use this programme, you could execute the commands written down in the Makefile.
Additionally, you might need to install the Python package manager pip. If any other file has to be installed, you might see it in the command prompt during the installation process.
Installation
To start the actual installation of the router, you have to download the current version of the Crossbar router. Just clone the repository into the desired local directory.
Next, navigate the command prompt/terminal to the local directory where you copied the crossbar repository into. Because you previously installed Make for Windows, it is easy using the commands from the Makefile now: Just type make install
. The installation process of the Crossbar router should start and be displayed on the screen. Additional software you might need would be shown.
Init and Start
After installation of the router, the command crossbar will be available. An initialisation of a new node is required. For this, invoke the command crossbar init
.
An initialised node could then be started. The command for starting is displayed at the end of the initialisation process. Alternatively, starting with the command crossbar start
usually works as well.
After waiting a short while, you should see that the local node configuration is applied successfully.
2018-10-07T07:23:32+0200 [Controller 22812] Booting node 2018-10-07T07:23:32+0200 [Controller 22812] Configuring node from local configuration 2018-10-07T07:23:32+0200 [Controller 22812] Starting 1 workers ... 2018-10-07T07:23:32+0200 [Controller 22812] Starting router worker "worker-001" 2018-10-07T07:23:32+0200 [Controller 22812] Starting new managed worker process for Router worker "worker-001" 2018-10-07T07:23:34+0200 [Router 33328] Starting worker "worker-001" for node "seifert-felix" with personality "standalone" 2018-10-07T07:23:34+0200 [Router 33328] Running as PID 33328 on CPython-IOCPReactor 2018-10-07T07:23:34+0200 [Router 33328] Entering event reactor ... 2018-10-07T07:23:34+0200 [Router 33328] Router worker session for "worker-001" joined realm "crossbar" on node router 2018-10-07T07:23:34+0200 [Controller 22812] Router worker "worker-001" process 33328 started 2018-10-07T07:23:34+0200 [Router 33328] Registered 41 procedures 2018-10-07T07:23:34+0200 [Router 33328] Router worker session for "worker-001" ready 2018-10-07T07:23:34+0200 [Router 33328] Starting router realm "realm-001" 2018-10-07T07:23:34+0200 [Router 33328] RouterServiceAgent ready (realm_name="realm1", on_ready=<Deferred at 0x2599175b828>) 2018-10-07T07:23:34+0200 [Controller 22812] Router "worker-001": realm 'realm-001' (named 'realm1') started 2018-10-07T07:23:34+0200 [Router 33328] Realm "realm-001" (name="realm1") started 2018-10-07T07:23:34+0200 [Router 33328] Starting role "role-001" on realm "realm-001" 2018-10-07T07:23:34+0200 [Controller 22812] Router "worker-001": role 'role-001' (named 'anonymous') started on realm 'realm-001' 2018-10-07T07:23:34+0200 [Router 33328] role role-001 on realm realm-001 started 2018-10-07T07:23:34+0200 [Router 33328] Starting router transport "transport-001" 2018-10-07T07:23:34+0200 [Router 33328] Creating router transport for "transport-001" 2018-10-07T07:23:34+0200 [Router 33328] Router transport created for "transport-001" 2018-10-07T07:23:34+0200 [Controller 22812] Router "worker-001": transport 'transport-001' started 2018-10-07T07:23:34+0200 [Router 33328] UniSocketServerFactory starting on 8080 2018-10-07T07:23:34+0200 [Router 33328] Starting "nodeinfo" Web service on path "info" of transport "transport-001" 2018-10-07T07:23:34+0200 [Controller 22812] Router "worker-001": web service 'nodeinfo' started on path 'info' on transport 'transport-001' 2018-10-07T07:23:34+0200 [Controller 22812] Local node configuration applied successfully!
Connection
Congratulations, you have started a local Crossbar router! Now, you could run microservices on your machine and connect them with this router. The URL for connecting is ws://127.0.0.1:8080/ws
and the realm is realm1
.
For developing a microservice connecting via WAMP, use one of the libraries mentioned on the WAMP homepage. For a quicker start, use an example in your preferred programming language.
You could also have a look on my GitHub page on how I connected to a local router – the connection details are written in the application.properties file.