Developing modern applications often requires us to separate processes along logical divisions. Architectural patterns such as Microservices and SOA (Service Oriented Architecture) have emerged as popular solutions to the common problem of breaking down monolithic structures into more strategic and manageable pieces. This process can often lead to other issues, however, typically related to communication between the disparate services. Since these different services exist as separate processes, often running on different machines, an easy to implement solution would be to create API endpoints for each of these services, allowing them to directly communicate with one another. There are many limitations to this strategy, including:
While smaller operations may not need to be concerned with these limitations, larger operation should consider a more robust, reliable and cost-effective method of inter-service communication. A great solution to these requirements is to implement a message queue. Message queues serve as a broker for messages between different applications / services, helps guarantee delivery, and removes the need for separate processes to be aware of one another. This means WAY fewer api-location maps and service contracts, further decoupling your services.
RabbitMQ is an open-source, tried-and-true message queue service that works on almost any machine. It requires very little memory, is easy to install, and runs perfectly on a cheap Raspberry Pi. This article will walk you through the process of installing RabbitMQ on a Raspberry Pi, which is a little more complicated to install on raspbian that it would generally be for other linux builds or operating systems. If you need help getting off the ground with setting up a Raspberry Pi, please read this article.
The fist thing we need to do is install a couple dependencies called erlang and logrotate. In your terminal, enter the following command:
$ apt-get install –y erlang logrotate
It is likely that there will be other dependencies that are needed for erlang and logrotate to run, so after running the above command you should enter a cleanup command to install any missing / failed dependencies:
$ apt-get -f install
Finally, we need to download the latest version of rabbitmq-server.deb. At the time this article was written, the most recent version number was 3.6.10. In a terminal on your RPi, navigate to your downloads folder and enter the following commands:
$ wget https://github.com/rabbitmq/rabbitmq-server/releases/download/rabbitmq_v3_6_10/rabbitmq-server_3.6.10-1_all.deb
$ dpkg -i rabbitmq-server_3.6.10-1_all.deb
Once these commands are finished running, you should now be all setup with your local RabbitMQ instance; the port you need to access the service defaults to 5672. In the next step, we will walk you through configuring the management console so you can manage users, view connections, manage resources and setup exchanges / queues.
Open a terminal in your RPI and enter the following commands, replacing variables (denoted by brackets) with actual values:
$ sudo rabbitmq-plugins enable rabbitmq_management
$ sudo rabbitmqctl add_user [newuser] [password]
$ sudo rabbitmqctl set_user_tags [newuser] administrator
$ sudo rabbitmqctl set_permissions -p / [newuser] ".*" ".*" ".*"
The above commands will perform the following actions:
Once this is complete, you can now access the management console by opening a browser and navigating to your RPI's internal IP addres, with the port 15672
. For people who may be new to computer networking concepts, you can find your devices internal IP address using the ifconfig
command. Once you locate this, simply type this into the address bar of a browser, add a colon (:) after it, then the port number. An example URL would be 192.168.1.55:15672
.