13. Why does app backend use Message Queue? 13. app backend Message Queue

Source: Internet
Author: User

13. Why does app backend use Message Queue? 13. app backend Message Queue
Many friends who have no practical project experience are unfamiliar with the message queue system. Message Queue is mentioned in many architectures. However, I don't know why message queue is used? What is a message queue? What are common message queue products?


Read this article to help you solve the above questions.


1. Why message queue?

Assume that a boss needs to complete a task. When processing this task, the task is divided into several small tasks, as long as these small tasks are completed separately, the entire task is completed.


When a small task is completed, it is found that it takes a lot of time to complete this small task, and the completion of this small task does not affect the completion progress of the entire task. As a result, the boss handed in this small task to a younger brother to do it, and then completed other tasks on his own.


In the above example, the boss is the background system, and the younger brother is the message queue system. It takes a lot of time for the background system to complete some small tasks, and it does not affect the entire task to be completed later, these small tasks are handed over to the Message Queue System.


In the actual app backend, such tasks as sending emails, sending text messages, and pushing are very suitable for the Message Queue System. You can think about whether these tasks require a lot of time and will not be completed later. Put these tasks in the queue to speed up the request response time.


2. How does a Message Queue work?

The message queue system generally has three roles: Queue Server, queue producer, and queue consumer.


The message queue system is similar to this scenario: there is an information conveyor that keeps running. At the starting point of the conveyor belt, worker a constantly puts information in a box, puts the box on the conveyor belt, and the box is transmitted to the terminal by the conveyor belt. At the end, worker B Extracts the information from the box for processing.


In the above scenario, the non-stop conveyor belt is the Queue Server, and worker a who keeps putting boxes at the conveyor belt start is the queue producer, worker B, who keeps taking boxes at the end of the conveyor belt, is the consumer of the queue.


The MQ server now has a large number of open-source applications, such as RabbitMQ, ZeroMQ, and redis.


Queue producers and service providers are clients developed for Message Queue servers. For example, RabbitMQ has clients developed for java, php, and other languages.


For example, in the app backend, use code to call the java client and place the text message to be sent in ZeroMQ. Here, the java client acts as the producer of the queue.


Write a daemon. In the daemon process, call the java client through code to continuously extract the text message to be sent from ZeroMQ and then send it out.


3. Some Common Message Queue Products

RabbitMQ:


It is an open-source Message Queue written using Erlang. It supports many protocols, including AMQP, XMPP, SMTP, and STOMP, which makes it very heavyweight, it is more suitable for enterprise-level development. At the same time, a Broker architecture is implemented, which means that messages are first queued in the central queue when they are sent to the client. It provides good support for Routing, Load balancing, and data persistence.


At the same time, RabbitMQ comes with a web monitoring interface that allows you to conveniently monitor queues.


Redis:


Although it is a key-value system, it also supports the data structure of queues, which can be seen as a lightweight Message Queue System.


In the app backend architecture, redis is widely used. If it is used as a message queue at the same time, it reduces the O & M cost.


ZeroMq:


The fastest message queue system, especially for scenarios requiring high throughput.


ActiveMQ:


Is a subproject under Apache. Similar to ZeroMQ, ZeroMQ can implement queues by proxy and point-to-point technology.


Bytes ---------------------------------------------------------------------------------------------------------------------------

Open the General Directory of the back-end articles of the linked app series to view all the original "app back-end" articles published by me.

【Author】 Zeng jiansheng
[QQ] 190678908
[QQ Group] 254659220
[Public Account] appbackend
[Sina Weibo] @ newjueqi
Blog http://blog.csdn.net/newjueqi


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.