In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what are the characteristics of message queues". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what are the characteristics of the message queue"?
What is a message queue?
Message queuing (Message Queue) is a way of communication between processes or between different threads of the same process. Processes or threads communicate through messages, and the message can be returned immediately after it is sent, and the message system ensures the reliable delivery of the information. The message publisher (producer) just publishes the message to the message queue regardless of who consumes it, and the message consumer (consumer) just gets the message from the message queue for further processing without managing who publishes the message. In this way, neither the publisher nor the user needs to know the existence of each other.
Message refers to the data transferred between applications. Messages can be very simple, such as containing only text strings, or complex, such as embedded objects.
Characteristics of message queues
By providing message passing and message queuing model, it can provide the functions of application decoupling, elastic scaling, redundant storage, traffic peaking, asynchronous communication, data synchronization and so on in distributed environment. As an important component of distributed system architecture, it plays an important role. The main features of message queuing are:
Asynchrony: asynchronize time-consuming synchronization operations by sending messages. The waiting time for synchronization is reduced.
Loose coupling: message queuing reduces the coupling between services. Different services can communicate through message queues without paying attention to each other's implementation details, as long as the format of the message is defined.
Distributed: through horizontal expansion to consumers, the risk of message queue blocking is reduced, and the possibility of a single point of failure for a single consumer is reduced.
Reliability: message queuing generally stores the received messages on the local hard disk (when the messages are processed, the stored information may be deleted according to different message queuing implementations), so that even if the application hangs or the message queue itself dies, the message can also be reloaded.
Asynchronous processing of message queuing application scenarios
Synchronous processing means that from the initiation of the request to the completion of the final processing, the caller of the request has been blocking synchronously waiting for the processing of the call to be completed.
Asynchronous processing means that during the processing initiated by the request, the client code has been returned and it can continue with its own subsequent operations without waiting for the call processing to complete.
For some operations that are time-consuming and do not need to return the results of the operation immediately (synchronously), the processing can be processed asynchronously through the message queue. This can delay the processing of the time-consuming operation and asynchronize the time-consuming operation without blocking the client program, which can continue to execute until the processing result is obtained, thus improving the processing performance of the client program.
The main purpose of asynchronous processing is to reduce the request response time, achieve non-core process asynchronization, and improve the response performance of the system.
Application decoupling
Using message queue, multiple producers can publish messages, and multiple consumers can consume messages and complete the whole business processing logic together. Producers only care about whether messages are correctly written into message queues. Consumers only care about getting messages from message queues, and then carry out processing logic. There is no need for direct interactive calls between producers and consumers, and there is no code dependency coupling.
The lower the coupling, the easier the program code is to maintain and expand.
Flow peaking
It is widely used in flash sale activity.
In flash sale activity, generally, due to the excessive instantaneous traffic, the server receives a large number of requests in an instant, and the traffic increases sharply. In this case, the relevant systems are likely to be unable to process requests or even crash. In order to solve this problem, message queues are usually added to the front end of the application.
The request is written to the message queue first, rather than directly processed by the business system, which makes a buffer, which greatly reduces the pressure on the business processing system.
The length of the queue can be limited. Generally speaking, there is a limit on the number of flash sale activity. Users who write to the queue cannot kill the goods in seconds. Such requests can be discarded directly and can directly return that the activity has ended or the goods have been sold out.
With message queuing, the system can continue to receive requests even as access traffic continues to grow. Although the messages generated by producers are faster than those consumed by consumers, they are buffered by message queues. In a short period of time, the processing power between producers and consumers will not affect each other, which can also ensure the stability of the system.
Message communication
Message queues generally have built-in efficient communication mechanisms, so they can be used for simple message communication, such as implementing peer-to-peer message queues or chat rooms.
Broadcast
If there is no message queue, every time a new business party intervenes, the interface needs to be co-invoked. With the message queue, it is only necessary to determine whether the message has been delivered to the queue. As for who wants to subscribe, it is a downstream matter, which undoubtedly greatly reduces the workload of development and co-tuning.
Log processing
Message queuing is used in log processing to solve the problem of a large number of log transfers (such as Kafka).
Transmission mode of message queue point-to-point mode (Point to Point)
The point-to-point pattern is used for point-to-point communication between message producers and message consumers. The message producer sends the message to a specific queue (Queue) identified by a name. The message is stored in this queue before it is delivered to the consumer. Queue messages can be placed in memory or persisted to ensure that messages can still be delivered in the event of a message service failure.
Characteristics of point-to-point mode:
There is only one Consumer per message, that is, once the message is consumed, the message is no longer in the message queue.
There is no dependence between the producer and the consumer. After the producer sends the message, whether the consumer is running or not, it will not affect the producer to send the message next time.
After successfully receiving the message, the consumer needs to reply successfully to the queue so that the message queue deletes the currently received message.
Publish / subscribe model (Publish/Subscribe)
The publisher / subscriber model supports the production of messages to a specific message topic. 0 or more subscribers may be interested in receiving messages from specific message topics.
In this model, publishers and subscribers do not know each other. Messages are available to multiple consumers, and there is a time dependence between publishers and subscribers. The publisher needs to establish a subscription in order to be able to subscribe to consumers. Subscribers must remain continuously active and receive messages.
Features of publish / click mode:
Each message can have multiple subscribers.
There is a temporal dependency between publishers and subscribers, and subscribers to a topic (Topic) must create a subscription before it can consume the publisher's messages.
In order to consume messages, subscribers need to subscribe to the role topic in advance and keep it running online.
Comparison of centralized message middleware
At present, in the production environment, the most commonly used message queues are ActiveMQ, RabbitMQ, ZeroMQ, Kafka, MetaMQ, RocketMQ and so on.
At this point, I believe you have a deeper understanding of "what are the characteristics of the message queue?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.