1、 Introduction to rabbitmq
Rabbitmq is an open source implementation of AMQP (Advanced message queuing protocol) developed by Erlang. It is an advanced message queuing protocol, an open standard of application layer protocol, designed for message oriented intermediation. Message oriented middleware is mainly used to decouple components. The sender of message does not need to know the existence of message consumer, so does the consumer.
Rabbitmq supports a variety of clients, such as. Net, Java, C, PHP, etc. Supporting Ajax plays an important role in storing and forwarding messages in distributed systems, and it also performs well in terms of ease of use, scalability and high availability.
2、 Role of rabbitmq
Bloggers believe that rabbitmq plays the following three important roles in the program world.
for instance:If you buy a product on the Internet (this process is very complicated, we only talk about part of the operation here), then the system needs to inform the inventory of the goods minus 1. At this time, the system may call the interface to handle the process (there is no problem with the process itself). In this process, there is a high coupling between the application system and the inventory. Obviously, this highly coupled operation is unacceptable for an order system. Frequent requests may lead to extremely low efficiency or even collapse of the system. At this time, MQ can solve our problem. We send the order message to the MQ service queue. The inventory system only needs to obtain the order information in the MQ service queue for processing. At this time, there is no coupling relationship between the application system and the inventory. Because MQ asynchronous processing mechanism can improve the efficiency of application system, the use of cluster can solve the problem of order concurrency.
First of all, let’s take a look at a picture
In the figure below, “P” is our producer and “C” is our consumer.The middle box is a queue – rabbitmq represents the message buffer held by the consumer. You can see that P sends the message to the Hello buffer, and C processes it as long as it wants.
3. Peak clipping
This cutting peak is not Xiao Feng in the eight parts of Tianlong mountain (^_ ^）。 What is peak shaving? Peak shaving can be interpreted as “flow peak shaving”, “peak shaving and current limiting”. How to cut peak
for instance:Let’s take the order system as an example. If there is a second killing activity (at this time, your system traffic is a rare peak), originally your system can process 10W data in one second, but in the peak traffic, the system data is far more than 10W, which may cause excessive server pressure and data processing problems. MQ can solve this problemThe second point is asynchronousIt is also introduced that MQ has a buffer, which we can use for peak clipping. We only need to do the data processing and current limiting operation in the business processing section. Then someone asked what to do if the number of seconds killed exceeds the number of goods. In the same way, we can use MQ to solve problems. In MQ, we can set a peak value for the goods. As long as the peak value is exceeded, it will prompt that the goods have been robbed and other information (this is similar to robbing red packets). As shown in the figure below
3、 Rabbitmq installation (client)
MQ download address: https://www.rabbitmq.com/download.html (official website).
The specific installation process blogger here will not repeat, said a few points for attention.
1. Before installing rabbitmq, you must first install Erlang. It is true that Erlang should be installed first. Careful friends may have found that rabbitmq is developed by Erlang, so you should install Erlang environment first. The download address is the same as MQ.
2. After installing Erlang, install MQ.
3. Be sure to activate and restart after installation. As shown in the figure
Open the application in the red box above and execute rabbitmq plugins enable rabbitmq_ Management, net stop rabbitmq & & Net start rabbitmq command.
4. The default port of MQ is 15672, and the default user password is guest.
5. If you want to create a new user, it is best to set it to admin.
Use after successful installation http://localhost : 15672 open the MQ client, and the following figure shows that the installation of the client is successful
See here is not a kind of MQ suddenly open-minded feeling.
Next: rabbitmq series essays –. Net MQ practice.