Message queuing makes it possible for applications to communicate asynchronously, by sending messages to each other via a queue. A message queue provides a temporary storage between the sender and the receiver so that the sender can keep operating without interruption when the destination program is busy or not connected.
What is message queuing?
Let’s start by defining message queues; how you can use a message queue and the benefits achieved when using message queues.
A queue is a line of things waiting to be handled — in sequential order starting at the beginning of the line. A message queue is a queue of messages sent between applications. It includes a sequence of work objects that are waiting to be processed.
A message is the data transported between the sender and the receiver application; it’s essentially a byte array with some headers on top. An example of a message could be an event. One application tells another application to start processing a specific task via the queue.
The basic architecture of a message queue is simple; there are client applications called producers that create messages and deliver them to the message queue. Another application, called a consumer, connects to the queue and gets the messages to be processed. Messages placed onto the queue are stored until the consumer retrieves them.
The role of message queuing in a microservice architecture
In a microservice architecture, there are different functionalities divided across different services, that offer various functionalities. These services are coupled together to form a complete software application.
Typically, in a microservice architecture, there are cross-dependencies, which entail that no single service can perform its functionalities without getting help from other services. This is where it’s crucial for your system to have a mechanism in place which allows services to keep in touch with each other without getting blocked by responses.
Message queuing fulfills this purpose by providing a means for services to push messages to a queue asynchronously and ensure that they get delivered to the correct destination. To implement a message queue between services, you need a message broker; think of it as a mailman, who takes mail from a sender and delivers it to the correct destination.
Benefits of a Microservice architecture
An increasing number of organizations are now going down the microservices road because it allows them to have a more agile approach to software development and maintenance. Microservices also make it easy for businesses to scale and deliver updated versions of their software.
Development and maintenance
Imagine that you have to build a huge, bulky billing application which will involve authentication, authorization, charging and reporting of transactions. If you divide your application across multiple services (one for each functionality), you will be able to separate the responsibilities and also give developers the freedom to write code for a specific service in any chosen language. Additionally, it will also be easier to maintain written code or make changes to the system. For example, if you are asked to update your authentication scheme, you will only have to add code to the authentication module and test it, without having to worry about disrupting any other functionalities.
Fault isolation in a Microservice
Another obvious advantage offered by a microservice architecture is its ability to isolate the fault to a single module. For example, if your reporting service is down, your authentication and billing services will still be up, ensuring that your customers can perform important transactions even when they aren’t able to view reports.
Message Broker — RabbitMQ
RabbitMQ is one of the most widely used message brokers, with over 35,000 production deployments worldwide and is considered one of the most reliable message brokers available. RabbitMQ acts as the message broker, “the mailman”, a microservice architecture needs.
Getting started with RabbitMQ on Manifold
A RabbitMQ message broker can be created at Manifold via the CloudAMQP resource. CloudAMQP automates every part of the setup, running and scaling of RabbitMQ clusters.
- Create a Manifold account, and a project, if you do not already have one.
- Create a CloudAMQP Resource and link the resource to the project. Which plan you want to use depends on your needs. CloudAMQP offers seven different plans, both dedicated clusters, individual servers and vhosts on shared clusters.
- You can try out CloudAMQP for free with the plan Little Lemur. You are also able to select the region for your instance.
The instance is created within 2 minutes and you can view all your instance information by opening the CloudAMQP Dashboard.
The dashboard includes details for your instance, which are needed when you want to connect to your message queue. Programming guides for different languages can be found here: https://www.cloudamqp.com/docs/index.html
The control panel offers various tools for monitoring and alarms. You can address performance issues promptly and automatically before they impact your business. CloudAMQP makes it easy to set up custom alarms via email, webhooks and external services. You can also, on dedicated plans, use the Diagnostic tool to verify your setup.
The optimal RabbitMQ Guide
CloudAMQP has created an E-book that can be downloaded for free: The Optimal RabbitMQ Guide. The book is divided into three parts;
The first part focuses on giving a gentle introduction to microservices and RabbitMQ, and how to use RabbitMQ on CloudAMQP. You will learn the most important RabbitMQ concepts and how RabbitMQ allows users to create products that match all of the demands made by the industry of both today and tomorrow.
The second part of the book is for the more advanced users. You will, after that part, be able to take full advantage of RabbitMQ. We talk about Best Practice recommendations for High Performance and High Availability and common RabbitMQ errors and mistakes. It’s also a deep dive into some RabbitMQ concepts and features.
The third part gives some real-world user stories from own experiences and a CloudAMQP customer’s point of view.
We hope that this book will help to take you even further on your message queuing journey.
Special thanks to Lovisa Johannson and the rest of the CloudAMQP team for submitting this post for us to publish on their behalf as part of Manifold’s 12 Days of Services.