Message Queue is a form of asynchronous communication between a message producer and a message consumer. A message queue, as an entity, is a place where messages are stored, and it is placed between a message producer and a message consumer. Message content can be anything, depending on the problem being solved and how the programmer wants to solve it. For example, messages can contain some information, commands, HTTP requests and who knows what else. In this blog, I will discuss software, or its components, as message consumers or producers.
Message queues allow asynchronous communication between consumer and producer, making this mechanism powerful. Asynchronous messaging means that the producer can send a message to the message queue and continue with their own work without thinking about the sent message. The sent message will be stored in the message queue until the consumer finds time to process that message. That means that producers do not need to wait for possibly busy consumers to process messages, which can speed up software.
There are many message-queue software implementations that you can use for your software, and some may have some additional features compared to others. Although they can have different features, most support common message queue variations that allow this mechanism to be suitable for solving many problems. For example, you can have the following:
The listed variations are common to message queue variations that can be combined to solve many complex problems.
There is a wide range of possibilities for message queue use. Some usual message queues usages:
This list is not complete, and there are endless possibilities.
I encountered the use of this mechanism at the very beginning of my career. I mostly used that for sending commands from one software component to another. The last time I used this mechanism, many producers created commands and put them as messages in message queues. On the other end, I had one consumer, as a separate software component, that waited for new messages. Upon arrival, the consumer would read the message and start the requested operation with the provided information. The idea behind using message queues was to decouple heavy processing because the consumer had to do a relatively slow job. We wanted that process to run independently of the application where the producers were, to keep our system fast.
As I said, the message queue mechanism is very powerful and can be used for solving various problems. It is not difficult to understand, and the main idea for writing this text is to encourage you to find out more about message queues if you have not heard about them before because you may come across a problem that can be solved with the help of this mechanism.