Table of contents
test environment:
操作系统: Window 10
工具:Pycharm
Python: 3.7
An overview of the basics of message queues
What is a message queue?
Messages (
Message
) refer to data transferred between applications. Messages can be as simple as just text strings, or more complex and may contain embedded objects.
Message queue (Message Queue —— MQ
) is a communication method between applications. Messages can be returned immediately after sending, and the message system ensures reliable delivery of messages. The message publisher only publishes the messageMQ
to , regardless of who gets it, and the message user onlyMQ
takes the message from , regardless of who publishes it. In this way, neither the publisher nor the user needs to know the existence of the other party.
I think the application here should be client application software such as App and PC software , sending messages to the server (server)
( 客户端
) Producer—( 消息队列
)—> Consumer ( 服务端
)
Why use message queues?
It can be seen from the above that message queue is an asynchronous cooperation mechanism between applications , so when do you need to use
MQ
it ?Taking the common order system as an example, the business logic after the user clicks the [Order] button may include: deducting inventory, generating corresponding documents, sending red envelopes, and sending SMS notifications. In the early stage of business development, these logics may be put together and executed synchronously. As the business develops and the order volume increases, the performance of system services needs to be improved. At this time, some operations that do not need to take effect immediately can be split out and executed asynchronously , such as issuing red envelopes, Send SMS notifications, etc. It can be used in this scenario
MQ
. After the main process of placing an order (such as deduction of inventory and generation of corresponding documents) is completed, a message is sent toMQ
let main process end quickly, andMQ
the message pulled by another separate thread (or byMQ
push message) ), and execute the corresponding business logic when a red envelope or text message is foundMQ
in .
The above is the case for business decoupling. Other common scenarios include eventual consistency , broadcasting , peak-shift flow control , and so on.
Understand the relationship between message queue servers and web servers
The understanding here is that the business is the priority, so the message queue is used. For comparison, Taobao double 11 , the order per second exceeds 500,000 . This is a bottomless pit for the performance requirements of the system, so the message queue is used. , to meet the performance requirements of the business is very necessary. Going a little deeper, it can be considered that orders are so-called high-concurrency operations, while red envelopes, text messages, etc. are delayed operations and belong to low-concurrency operations, so how should the server handle high-concurrency operations ? That is to use Web
the server's load balancing service , and to deal with low concurrent operations , you need a message queue server to handle it, such as Rabbit MQ
(rabbit message queue server)
Off topic: Enterprise-level understanding of server and client
Learn about web servers
Commonly used web servers: Apache
, Nginx
, Tomcat, Lighttpd, Zeus, IIS
Web server development language link: https://www.oschina.net/
You can find the web server development language
eg through this link:
Understand the difference between web frameworks and web services
Web
The main function of the server ( Web server
) is to receive client requests, and Web
the framework ( Web framework
) is to process the requests received by the web server, generate HTML
content, pass the generated HTML
content to Web
the server, and then Web
return it to the client (browser) by the server .
Here I have to mention the Python Web
frameworks - Django
, Flask
, web.py
, these three python Web
frameworks ( frame ranking links ), generally novices can learn the first three, and the other frameworks depend on their own interest and ability.
①The role of using
Web
the framework: it is to facilitate programmers to efficiently build and automateHTML
content —to generate user-friendly content;②The
Web
main function of the server ( Web server ): to receive client requests;
Personal understanding of framework and server B/S architecture message queue:
Using
Web
a server is a functional independence ofWeb
the framework generatingHTML
content andWeb
the server receiving messages and sending content. The production is handed over to the manufacturer, and the express delivery is handed over to the logistics company. It is easier to understand, but it is still a little bit meaningless. A deeper point is that every time the process of the server is switched, it will be in the framework of the production content and the reception Messages and content are switched between the two processes of the server , then during the switching process, for a period of time, the server completely belongs to the process of one of the framework and the server , specifically, it is dedicated to the process of the two One service, then you should be aware that at that time the server serves one of the two processes, resources (multi-core chip computing, memory, disk storage, etc.) try to serve one of the processes, if it is very A powerful server (two words are expensive) can better reflect the performance gap. Therefore, for high-concurrency operations of the B/S architecture , a high-performance server must be required to execute.HTML
HTML
Web
HTML
Web
Web
Web
Web
The high performance here requires knowing Web
what programming language the server is written in. Since the performance requirements are applicable here, the server developed in C/C++Web
language is better. This can be done by comparing the performance speed of the programming language. Find out which Web
servers perform better, of course, sometimes it depends on which Web
server to use.
List the top three programming languages for performance:
C
↑C++
↑Java
↑
I won’t write about it later, you can search on the Internet. Of course, you don’t need to consider the performance of programming languages. You can also know that except for the web servers written in these programming languages, you can roughly guess their performance.
Personal understanding of the business logic of the browser B/S architecture:
Client Brower
(browser) - serverServer
RabbitMQ is a message queuing system developed based on Erlang language