A brief description of message queues
Message queue distributed database is a key component in distributed architecture, which deals with coupling, multi-thread information and total traffic cutting. To achieve superior performance, high availability, retractable and final consistency architecture. Distributed databases are indispensable for large and medium distributed architectures.
Second, message queue application field
Let’s take a look at some of the common application scenarios of message queues. The scenarios can be divided into four scenarios: multithreading solution, using decoupling, total flow cutting and information communication.
2.1 Multi-threaded Solution
The situation shows that: after registration, new users must push the email application for registration and push basic information. There are two traditional methods: serial communication method and parallel processing method
Serial communication method
After the basic information is loaded into the database and the query is successful, the application for registration email is pushed, and then the application for registration short message is pushed. After all daily tasks are carried out, the information content is returned to the mobile client
Serial communication method
Parallel processing method
After the basic information is loaded into the database successfully, the actual operation of push application registration email and push application registration short message is carried out at the same time. After all daily tasks are carried out, the message content is returned to the mobile phone client. Compared with serial communication method, parallel processing method can improve implementation efficiency and reduce implementation time.
Parallel processing method
The above can be found that, assuming that the implementation time of the three practical operations must be 50ms to clear the Internet elements, then the final implementation of the serial communication method must be 150ms, and the parallel processing method must be 100ms.
Since the total number of requirements that THE CPU solves in unit time is consistent, assuming that the amount of cargo volume of THE CPU is 100 per second, the requirements that the serial communication method can implement in 1 second is 1000/150, not 7 times. The amount of requirements that can be implemented by the parallel processing method within 1 second is 1000/100, which is 10 times.
It can be seen from the above that the traditional serial communication and parallel processing methods will suffer from the limitations of system software characteristics, so how to solve this problem?
You have to introduce message queues, solve the domain model that is not necessarily multithreaded, and update the steps out as well
Message queues are introduced, and multithreading resolves information
On the basis of the above steps, the customer response speed is basically equivalent to the customer data information into the database query time, push applying for registered email and push for registration information of the message after load the message queue, you can return to implement results, load the message queue time quickly, basically can be ignored, It is also able to increase the freight volume of the system software to 20QPS, nearly 3 times higher than the serial communication method, and 2 times higher than the parallel processing method.
2.2 Apply decoupling
Scenario: after the customer submits the order, the order management system must notify the inventory system.
The traditional approach is: order management system to enable the inventory system socket. As shown below:
Traditional method: Enable inventory socket
The traditional method has the following defects:
-1. Assume that the inventory system browsing is unsuccessful, then the order information is unsuccessful in reducing the inventory, resulting in the unsuccessful establishment of the order information
-2. Excessive coupling between order management system and inventory system
How to solve the above defects? Message queues must be introduced, and the architecture after message queues are introduced is shown in the following figure:
Message queues are introduced to complete application decoupling
Order management system: after the customer submits the order, the order management system carries out data information distributed lock solution, then loads the information into the message queue, and returns to the order information establishment successfully
Inventory system: the application of pull/push method, obtain the submitted order information content, inventory system according to the order information, the actual operation of inventory.
If the inventory system does not work properly when the order is submitted. Do not jeopardize all normal order submission, because after the order submission, the order management system load message queue will not care about its actual operation. Thus the order management system and inventory system to complete the use of decoupling.