Why use message queues

Reference:
https://blog.csdn.net/whoamiyang/article/details/54954780

1. Background

RabbitMQ is an open source implementation of AMQP (Advanved Message Queue) developed by erlang.

2. Application scenarios

2.1 Asynchronous processing

Scenario description: After users register, they need to send registration emails and registration text messages. There are two traditional methods: 1. Serial method; 2. Parallel method
(1) Serial method: After writing the registration information into the database, send the registration Email, and then send the registration SMS, the above three tasks are all completed before returning to the client. The problem with this is that email, SMS is not necessary, it is just a notification, and this approach makes the client wait for something that is not necessary to wait.
write picture description here

(2) Parallel mode: After the registration information is written into the database, while sending emails, a short message is sent. After the above three tasks are completed, it is returned to the client. The parallel method can improve the processing time.
write picture description here

Assume that the three business nodes use 50ms respectively, the serial time is 150ms, and the parallel use time is 100ms. Although the processing time has been improved, as mentioned earlier, emails and text messages have no effect on my normal use of the website, and the client does not need to wait for the completion of the sending to display the registration success. Return.
(3) Message Queue After the
introduction of the message queue, the business logic that is not necessary for sending emails and short messages is asynchronously processed
write picture description here

It can be seen that after the introduction of the message queue, the user's response time is equal to the time of writing to the database + the time of writing to the message queue (which can be ignored). After the introduction of the message queue, the response time is 3 times that of the serial , is twice the parallel.

2.2 Application decoupling

Scenario: Double 11 is a shopaholic festival. After the user places an order, the order system needs to notify the inventory system. The traditional method is that the order system calls the interface of the inventory system.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325283216&siteId=291194637