Message middleware MQ

1. Message queue review

Message queue middleware is an important component in distributed systems. It mainly solves problems such as application decoupling, asynchronous messaging, and traffic shaving, and achieves high performance, high availability, scalability, and eventual consistency architecture.

Insert image description here

1. Currently, the most commonly used message queues are ActiveMQ, RabbitMQ, ZeroMQ, Kafka, MetaMQ, and RocketMQ.

2. How to use message middleware and when to use it is a question. Using message middleware indiscriminately increases the complexity of the system. If you cannot use message middleware well, it is better not to use it.

3. Message middleware uses an efficient and reliable message passing mechanism for platform-independent data exchange, and integrates distributed systems based on data communication. By providing message passing and message queuing models, it can expand inter-process processes in a distributed environment. Communication, for message middleware, the common roles are roughly Producer (producer) and Consumer (consumer).

2. What are the characteristics of message queue?

1. First in, first out: First in, first out is a characteristic of the queue. It cannot be first in, first out, and it cannot be said to be a queue. The order of the message queue is basically determined when it is added to the queue. Generally, manual intervention is not required. Moreover, the most important thing is that only one piece of data is in use . , which is why MQ is used in many scenarios

Insert image description here
2. Subscription: Generally it is the broadcast mode of MQ, similar to the observer mode of Java. Publish and subscribe is a very efficient processing method. If no blocking occurs, it can basically be regarded as a synchronous operation. This processing method can very effectively improve server utilization. Such application scenarios are very wide.

Insert image description here
3. Persistence: Persistence ensures that the use of MQ is not just an auxiliary tool for some scenarios, but allows MQ to store core data like a database.
Insert image description here

4. Distributed: In today's usage scenarios of large traffic and big data, server software that only supports single applications is basically unusable. Only by supporting distributed deployment can it be widely used. Moreover, MQ is positioned as a high-end Performance middleware

3. Message queue communication mode

1. Point-to-point communication point: Point-to-point mode is the most traditional and common communication method. It supports multiple configuration methods such as one-to-one, one-to-many, many-to-many, many-to-one, etc., and supports multiple topologies such as tree and mesh. structure

Insert image description here

2. Publish/Subscribe mode: The publish/subscribe function makes the coupling relationship between the sender and the receiver looser. The sender does not need to care about the destination address of the receiver, and the receiver does not need to care about the message. The sending address only sends and receives messages based on the topic of the message. Among the MQ family products, MQEventBroker is a product specifically used for data communication using publish/subscribe technology. It supports two methods: queue-based and direct-based TCP/IP. publish and subscribe

Insert image description here

3. Cluster: A cluster is similar to a domain. When communicating between queue managers within the cluster, there is no need to establish message channels between each other. Instead, cluster channels are used to communicate with other members. This greatly simplifies system configuration

4. Why use message queue

1. Application decoupling: The traditional approach requires the execution of these business things in sequence. If one of the steps is abnormal (for example, the user's mobile phone is not turned on or the express company interface fails), it will delay or even interrupt the entire deposit process, seriously affecting the user experience.
Insert image description here

If the interface layer receives the deposit data and writes the message to MQ, and the subsequent three subsystems consume and process it separately, this problem will be perfectly solved, and subsystem failures will not affect the upstream system! This is " decoupling "

2. Asynchronous: For example, after express delivery, the user will finish immediately. He will not wait to send a text message or notify the courier company to finish. He will directly deliver the message to MQ, and then it will end directly. Specifically, the system fee will be deducted and subsequent Notifications are all asynchronous operations and do not require users to care. This is to convert the user's synchronous operations into asynchronous operations.

Insert image description here

If all synchronous operations take 15 seconds, and are sent to MQ and handed over to the system for asynchronous processing, the user only needs 1 second to complete the operation.

3. Traffic peak shaving: Just like when users deliver express delivery, the peak value reaches 40W per second, but our subsequent processing business can only be 20W per second, and the remaining 20W is accumulated in MQ. This is the very important traffic peak shaving capability of MQ. , let the background process the user's peak traffic slowly, and MQ assumes the role of a buffer

Insert image description here
Just like the waveform chart below, if the peak concurrency requested by the user is 40W, and the system's carrying capacity can only reach 30W, you can use MQ to cut the peak, and cut the system's maximum concurrency peak of 40W to only 200,000. It’s the practice of exchanging time for space
Insert image description here

5. What are the disadvantages of message queue?

1. Reduced system availability: The message queue acts as a middleman in the system. If the middleman suddenly loses contact, the other two parties will be at a loss, and ultimately the system will not be able to interact with each other.

Insert image description here

Just like when we deliver express, if there is a problem with MQ, then our entire system call link will be disconnected, and the front and back ends will not be able to communicate.

3. Consistency problem: The system needs to ensure data consistency between express delivery, system fee deduction, notifications, etc. If the system SMS notification and express notification are executed successfully, but the system fee deduction fails, data inconsistency will occur.
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_44702984/article/details/131615351