This is the 28th day of my participation in the August Text Challenge.More challenges in August

What is a message queue

Messages refer to data that is passed between two applications. Data types can take many forms, ranging from just text strings to embedded objects.

A Message Queue is a container that holds messages during their transmission. In message queues, there are usually two roles: producer and consumer. The producer is only responsible for sending data to the message queue and does not care who takes it out of the message queue for processing. The consumer is only responsible for pulling the data from the message queue, he doesn’t care who sent the data.

Why message queues

There are three main functions:

  • Decoupling. As shown in the figure. Suppose that systems B, C, and D all need data from system A, so system A calls three methods to send data to B, C, and D. Now, system D doesn’t need it anymore, so you need to delete the relevant code in system A. Let’s say there’s A new system E that needs data, and system A has to add the code that calls system E. To reduce this strong coupling, MQ can be used, where system A simply sends data to MQ and other systems get it from MQ if they need it.

  • Asynchronous. As shown in the figure. When A client sends A request, system A invokes system B, C, and D. If the request is synchronized, the response time is the sum of system A, B, C, and D, that is, 800ms. If MQ is used, system A sends data to MQ and can then send A response back to the client without having to wait for A response from systems B, C, or D, which can greatly improve performance. MQ can be used for non-essential services such as sending SMS messages, sending emails, and so on.

  • Peak clipping. As shown in the figure. This is actually an important application of MQ. If 5000 requests are sent to system A during A period of time, system A will send 5000 SQL requests to MySQL for execution. MySQL cannot process such A large number of requests, and MySQL will crash, resulting in system breakdown. If MQ is used, instead of sending SQL directly to the database, system A sends data to MQ, where it is acceptable to backlog data for short periods and then process it by pulling 2000 at A time by the consumer, preventing the system from crashing due to the large number of requests sent directly to MySQL during peak request periods.

Three, RabbitMQ features

RabbitMQ is an open source message middleware that implements AMQP(Advanced Message Queuing Protocol) in Erlang. First of all, know some of the features of RabbitMQ.

  • Reliability. Support for persistence, transport confirmation, release confirmation and more ensures the reliability of MQ.
  • Flexible message distribution strategy. This should be a feature of RabbitMQ. Messages are routed by Exchanges (switches) before they enter MQ. The message distribution strategies include simple mode, work queue mode, publish and subscribe mode, routing mode, and wildcard mode.
  • Cluster support. Multiple RabbitMQ servers can form a cluster to form a logical Broker.
  • Multiple protocols. RabbitMQ supports a variety of message queuing protocols, such as STOMP, MQTT, and more.
  • Supports multiple language clients. RabbitMQ supports almost all common programming languages, including Java,.NET, Ruby, and more.
  • Visual management interface. RabbitMQ provides an easy-to-use user interface that allows users to monitor and manage message brokers.
  • Plug-in mechanism. RabbitMQ comes with a number of plug-ins, which you can extend or write your own.

Thank you for watching, if there is a mistake in the article, welcome to the comment section to communicate. If this article has helped you, please like it at 👍.