RabbitMQ core concepts and working principle understanding

Introduction to RabbitMQ

Before introducing RabbitMQ, we need to introduce MQ. What is MQ?

The full name of MQ is Message Queue, which can be understood as the meaning of message queue. Simply put, it means that messages are delivered in a pipeline.

RabbitMQ is a message queuing service that implements the AMQP (Advanced Message Queuing Protocol) advanced message queuing protocol, using Erlang language.

So if you want to use RabbitMQ, you need Erlang environment and RabbitMQ, the official website download is too slow, here is the download link ribbitMQ+Erlang download

Benefits:

1. Improve system response speed

Producers only need to hand over their own messages to MQ, and then they can do other things without waiting for the processing results.

2. Improve system stability (based on microservices)

For example, in an e-commerce system, a user places an order to a merchant, and under normal circumstances, the merchant takes the order, but if the merchant system goes down, the user's order is unsuccessful, and Papa Ma is earning less money. You say it is not annoying. So joining MQ and placing an order to MQ means that the merchant is down, and the order will be received after the merchant's system restarts.

3. Asynchronization, decoupling, and peak elimination

Asynchronization: User registration can send emails and text messages separately, not in series

Decoupling: Microservices use MQ coupling to reduce

Eliminate peaks: kill error pages in seconds

For example

I don’t understand it. Let’s talk a little bit. In fact, RabbitMQ is an intermediary.

For example, if you have a 1,000-square-meter house under your name (then you will definitely not read this article) to sell, what would you do?

1. You will find a real estate agency and tell the agency that you want to sell a 1,000-square-meter house for 200 million, and the agency will provide you with satisfaction;

2. The intermediary receives the news that you are going to sell the house, and at the meeting they will publish a message in the system, "Someone has sold a house, 1000 square meters, 300 million" (It's really dark!!!)

3. There was a local tyrant who just wanted to buy a house, and then he was paying attention to the real estate information every day. When suddenly he saw a message from the agency, he looked at it and thought it was too expensive, and then wait.

   Or a lot of people are paying attention to this real estate information, and they all think it's quite expensive when they see this real estate information.

So RabbtiMQ is the intermediary (of course it is more conscientious)

Among them, there are several concepts of RabbitMQ implied.

Important concepts of RabbitMQ

Producer (Producer)-the person who sells the house: the application that sends the message.

Consumer (Consumer) ------ the person who pays attention to the information of the intermediary: the application that receives the message.

Queue (Queue)------intermediary system: a buffer for storing messages.

Message (Message)-------room information: the information sent by the producer to the consumer through RabbitMQ.

Connection -------- Seller's phone: TCP connection to connect RabbitMQ and application server.

Channel (Channel) ------ The medium (mobile phone, computer) to get the message: a virtual channel in the connection. When you send or receive messages through the message queue, this operation is carried out through the channel.

Exchange (Exchange)-------Intermediary (customer manager): The exchange is responsible for receiving messages from producers and distributing them to the corresponding message queue according to the exchange type. To achieve message reception, a queue must be bound to an exchange.

Binding (Binding)-----The client manager publishes information in the intermediary system-: Binding is an associated connection between the queue and the exchange.

Routing Key ------ Different intermediary information channels that consumers pay attention to: The routing key is a key for the exchange to view and decide how to distribute messages to the queue according to the key. The routing key can be said to be the destination address of the message.

RabbitMQ usage scenarios

1. In the spike scenario, if there are too many visits at the same time, use MQ to do peak shaving, that is, after reaching a certain value, you will directly jump to the friendly error page, and the previous data will go to MQ to queue up, such as hunger marketing. Play well millet

2. Subscription mechanism, for multiple people to monitor a service to get the news of interest, similar to a subscription account or an official account

3. For registered users, you need to send emails and text messages separately after registration

Communication diagram

RabbitMQ core

As we can see from the above example, there are actually three roles here: producer (seller), consumer (person who pays attention to intermediary news), and MQ (intermediary, which contains various functions)

The producer only needs to tell MQ that I want to sell the house and what the price is, and then I can pay MQ with full authority, and then may go to do other things, such as buying a piece of land, without waiting to see who buys it.

Consumers only need to subscribe to MQ news to know who is going to sell the house and what the price is

MQ contains many functions to support the delivery of messages.

So we see that MQ is the intermediary that is the key.

So what is the core strength of the intermediary? The boss or the employee? The answer, of course, is the employees, that is, the account managers mentioned above. There are not many account managers who collect information for the boss and who step on the plate for the boss (intermediary technical term). All employees are the core, that is, the exchange in MQ (Exchange)

Now let's talk about what this Exchang is? What can you do? Let's look at the next article. . . . . .

 

 

Guess you like

Origin blog.csdn.net/qq_32923295/article/details/115366390