In this tutorial we shall learn about Message Queue, why it is used, how it works and some of the open source tools Message Queue.
Nowadays big Monolithic Architecture are converted into Micro-service Architecture.
Because of this communicating between each microservice is very critical. Nowadays the data size is also increased, it is not possible to get all the data by AJAX calls or any other method.
Hence we need an architecture where there is seamless communication between multiple services and should be asynchronous.
Hence message queue can be said as a service to service asynchronous communication between multiple services.
Working of Message Queue:
For every producer, there will be a consumer waiting for the data. Once the message is received to the consumer, it will delete the message. Message queues are also fault tolerant, in case of system down, the messages can be retrying.
Example of where the message queue can be used:
In this example, we shall consider a Burger Shop.
Usually, in a burger chain the flow will be like below:
There will be a person that will take the order, and another person to fulfill the order. While the other person is fulfilling the order, they don’t stop taking the order. Hence taking order should be an async task, because, we cannot tell the customer to wait until the first order is completed. So when the customer gives the order, those orders are kept in a queue and an acknowledgment is given to them to let them know that their order has been received and is under process.
But once the Burger Shop getting more customers, they will add more persons to take the order from multiple points. All the orders will be maintained in one queue and will be served First come first serve basis.
Now consider a scenario, where one of the counters is down. Immediately the customers can go to another counter and order the burger. Thus maintaining data persistence and fault tolerance.
The communication between the order counter to the Queue server to the order fulfillment is taken care by message queue.
Open Source Tools for Message Queue:
Apache ActiveMQ
RabbitMQ
Apache RocketMQ