DEV Community

Cover image for A brief introduction to Message Queue
Pragya Sapkota
Pragya Sapkota

Posted on • Originally published at pragyasapkota.Medium

A brief introduction to Message Queue

A message is data used when two or more parties interact. A queue is a line of things in a sequence — waiting to be looked at. Hence, a message queue is a sequential line of messages sent between applications. For a formal definition, a message queue is an asynchronous service-to-service communication used in serverless and microservices architectures. When the system is large, multiple microservices run across it and communication becomes messy. To solve the problem, a separate system — Message Queue is implemented for data communication.

The most common example of a message queue is Apache Kafka, and some others are Amazon SQS, Apache RocketMQ, JORAM, and RabbitMQ. Typically, we publish our data or the messages in them and they will automatically notify the user with data.

Characteristics of a message queue

  • Messages are stored in the queue by the producer until it is processed by the user and then deleted.

  • Each message is processed once by a single user.

  • Queues can be used for fault tolerance as well. If there is a service outrage, the requests can be re-tried.

  • A message queue can decouple heavyweight processing, provide a lightweight buffer, batch work, or smooth the spiky workloads. The applications of modern cloud architecture are decoupled into small independent building blocks. This way, they are easy to develop, deploy, and maintain. The message queue is responsible for the communication and coordination of these distributed applications.

Way of communication with message queue (step-by-step)

  • Either create a message queue or connect to an existing one.

msgget()

  • Write in the queue.

msgsnd()

  • Read from the queue.

msgrcv()

  • Perform control operations on the queue.

msgctl()

Advantages of the message queue

  • Communication protocols are not required.

  • It can be used to quickly build new applications by reusing the building blocks.

  • Improved performance

  • Reliability

  • Scalability

  • Easy decoupling

  • Rate limiting

Conclusion

The data under the message queue are generally small and can be in any form — requests, replies, error messages, or plain information. The message stays until the user retrieves it and does something with it. Since a single message can be processed only once by a single user, a message queue is also known as “one-to-one” or “point-to-point” communications. If there is a case where the message needs to be processed by more than one user, the message queue is combined with Pub/Sub messaging in a fanout design pattern.

I hope this article was helpful to you.

Please don’t forget to follow me!!!

Any kind of feedback or comment is welcome!!!

Thank you for your time and support!!!!

Keep Reading!! Keep Learning!!!

Top comments (0)