PHP Message Queue

Source: Internet
Author: User
Message Queuing MQ, essentially a queue, its simplest operation is to join and out of the team, both in accordance with the procedures to determine when and what conditions, and when the conditions of the team. In other words, if you encounter a scenario in which the queue system and the business requirements of the outbound system are inconsistent, you can consider whether to use Message Queuing to implement it. There are a number of scenarios that can be applied, and here are a few common scenarios and explanations.

One: Asynchronous processing, application decoupling, distributed

Scenario: The primary business does not care when dealing with the business.

Cases: The relationship between order systems, logistics systems, financial systems, and operational logging systems in e-commerce systems.

The popular explanation: Xiao Ming is a cake clerk. After he made the cake, he put it in the window, marked "Done" on the corresponding order, and went on to make the next cake, not concerned about how the cake was sold, nor what time it was sold.
Implementation: Use a queue of middleware or intermediate system to store several business systems of the common parts, and processing independently. Each system's processing progress can be recorded using its own independent tag. After all the systems have completed operations, the team is out of action, or persisted in storing the data.

Note: It is important to consider the disaster tolerance of the intermediate data, and ensure that the business process can recover when the failure occurs and resumes. Ensure that each piece of data can be processed correctly.

Two: Peak handling

Scenario: Traffic is unbalanced at every point in time

Case: seconds kill, snapping

Explanation: Xiaoming makes the cake time is long, the order arrives to register as a list first, then sequentially produces, the order quantity is too big, will temporarily hang out "has sold" the brand.

Implementation: Use a single-threaded tool to queue business requirements. When the business request reaches the threshold, a friendly hint is given and the user's demand is rejected.

Note: For the peak demand, you can hang out "temporarily unable to buy, please wait" and other tips to prevent traffic impact on the subsequent business. For seconds to kill the need to stop, you need to consider the problem of super, you can add a quota counter, or when the number of seconds to kill the quota is full, issued a second kill the completion of the mark, the subsequent processing program detects the completion of the tag, then the subsequent processing.

Three: Delivery Guarantee

Scenario: The content needs to be strictly enforced, and the execution succeeds, the execution is unsuccessful or the interrupt is resumed.

Case study: Banking, financial systems, systems that need to improve disaster resilience

Explanation: The cake produced by Xiao Ming needs the customer to be inspected and signed before he can continue making the next cake.

Implementation: The queued system writes the business requirements to the message queue, which is the next business process. The subsequent handlers process the contents of the queue and issue a "complete license" after processing is complete. The contents of the message queue can only be removed from the message queue if the "complete permission" is obtained.

Note: Focus on disaster-tolerant-related issues, such as business recovery issues and repetitive processing issues.

Four: Sort Guarantee

Scenario: The content in the message queue is in a strict order.

Case: Queuing system

Explanation: The order of making cakes by xiaoming needs to be made in a single order Strictly.

Implementation: The queued system writes the content to the message queue, and according to a single line, according to the first-in-order to put forward data and subsequent processing.

Note: A single thread is required to ensure that only one line is available.

V: Extensibility

Scenario: Add a new Subscriber when using the publish-subscribe model
Case: After registering the user, send a successful text message in the model, append a Send email function
Implementation: The middle tier of a message is subscribed to by multiple consumers, who then publishes the information to the middle tier. Consumers who subscribe to this middle tier can receive this message and follow up with them. In this structure. If you want to add a subsequent processing component of a message, you only need to subscribe this component to the middle tier
Note: Ensure that there is no deep coupling between the services to prevent interference during expansion.

The above is a number of common scenarios of Message Queuing, Message Queuing can be used to ping the differences between systems, improve system stability, the application of many scenarios.

In the Message Queue media selection, it is recommended that students do not have to be in the beginning to maximize the conditions and objectives, must be what conditions to perfect the perfect solution to the problem, the program still needs a long-term maintenance and optimization process.

While Redis is still very serious in situations such as high traffic and large amounts of persistent data, it is recommended that you learn the queue from Redis, and that in the course it is only through the process to understand the queue's application scenarios and ideas, any online project is constantly optimized and perfected, If you want to solve all the problems through a set of video, I am sorry, I can not do, each job needs and application scenarios are different, so in the different needs of the specific needs to improve.

When determining the queue requirements, it is necessary to determine when the queue conditions are applied when adding counter fields to determine the length of the current queue each time the queue is pressed in, and if the number exceeds the specified number of seconds to kill the program is not in the queue.

In actual use, there is no need to deliberately pursue where to add Message Queuing. and should be in accordance with the actual situation, in the separation and decoupling of business, as well as some special requirements of the reasonable choice and use.

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.