MQ theory

Today bring you a brief look at a simple theoretical knowledge MQ (Message Queue Message Queue) is.

What is MQ

Message Queue (Message Queue, referred to as MQ), literally speaking, is essentially a queue, FIFO first in first out, but the content is stored in message queue only.

Its main purpose: communication between different processes Process / thread Thread.

Figure:

Here Insert Picture Description
Producer: message producer, responsible for generating and sending a message to the Broker;

Broker: Message processing center. Responsible for message storage, acknowledgment, retries, etc., which typically include multiple Queue;

Consumer: news consumers, is responsible for getting the message from the Broker, and dealt with accordingly;

characteristic:

Induction of
the synchronous time-consuming operation, by way of sending a message performs asynchronous processing. Reducing the waiting time synchronization.

Loosely coupled
message queue reduces coupling between services, different services may communicate through the message queue, without concern for another implementation details, as long as the good news format definition line.

Distributed
by lateral extensions to the consumer, to reduce the risk of blocking message queue, and the possibility of single point of failure (message queue itself may of course also be made distributed cluster) individual consumers.

Reliability
message queue message received will typically stored on a local hard disk (when the message has been processed, the stored information to achieve depending on the message queue, it is possible to delete it), so that even if the application itself is linked to the message queue or hang out, the message can be reloaded.

Why would the message queue

1. When the transfer of messages between different processes (Process), high degree of coupling between the two processes, a process change, caused by another process must be modified, in order to isolate these two processes, the process of disengagement between the two a layer of (a module), all messages between two processes, must be transmitted through the message queue, modify one single process, without affecting the other;

2. When passing messages between different processes (process), in order to achieve standardization, standardization of the format of the message, and a process to accept too much of a message can not be processed at once, and there is also the order, must be received the message queue, gave birth to the fact that the message queue;

MQ defects

1) The system is more complex, more than one component MQ

2) a longer message transmission path, the delay will increase

3) reliability and reproducibility mutually contradictory message, the message is not lost no weight is difficult to guarantee the same time

4) upstream of the downstream can not know the results, and this is very deadly

The caller dependent on real-time business scenario execution result, use call instead of MQ.

MQ advantage

1) need not reserve buffer, the task execution upstream end, a downstream task is always performed at a first time

2) dependent on a number of tasks, is dependent on a number of tasks are handled well, you only need to subscribe to relevant information

3) has the task execution time, you do not need to adjust the downstream task execution time

MQ message is used to transmit an upstream task execution completion is not true for transmitting input and output data.

When not in use MQ

The results of real-time upstream attention

When to use MQ

1) data-driven task dependencies

2) upstream of the results of multiple downstream do not care

3) a long time execution returns asynchronously

MQ framework is very much more popular there RabbitMq, ActiveMq, ZeroMq, kafka, and Ali open source RocketMQ.

Guess you like

Origin blog.csdn.net/weixin_42236165/article/details/92087857