Download and install RabbitMQ and study notes in Silicon Valley (reading this article is enough!)

1. RabbitMQ entry flow chart

insert image description here

1.1, what is a message queue

informationRefers to the data passed between two applications. The type of data can take many forms and may consist of just text strings or embedded objects.

message queue(Message Queue)" is a container that saves messages during message transmission. In a message queue, there are usually two roles, producer and consumer. The producer is only responsible for sending data to the message queue, who takes data from the message queue He doesn't care about processing. The consumer is only responsible for taking out data from the message queue for processing, and he doesn't care who sent the data.
insert image description here

1.2 Why use message queue

There are three main functions:

  • decoupling. as the picture shows. Assume that systems B, C, and D all need data from system A, so system A calls three methods to send data to B, C, and D. At this time, system D is no longer needed, so the relevant code needs to be deleted in system A. Assuming that there is a new system E that needs data at this time, system A needs to add codes to call system E. In order to reduce this strong coupling, MQ can be used. System A only needs to send data to MQ. If other systems need data, they can get it from MQ.
    insert image description here
  • asynchronous. as the picture shows. When a client request is sent in, system A will call systems B, C, and D. If the request is synchronized, the response time is the sum of systems A, B, C, and D, which is 800ms. If MQ is used, system A sends data to MQ, and then can return a response to the client, without waiting for the responses of systems B, C, and D, which can greatly improve performance. For some non-essential businesses, such as sending text messages, sending emails, etc., you can use MQ.
    insert image description here
  • Clipping. as the picture shows. This is actually a very important application of MQ. Assuming that the number of requests of system A increases sharply in a certain period of time, and 5,000 requests are sent, system A will send 5,000 SQLs to MySQL for execution. Of course, MySQL cannot handle such a huge request, and MySQL will crash. lead to system paralysis. If MQ is used, system A no longer directly sends SQL to the database, but sends data to MQ. It is acceptable for MQ to accumulate data in a short period of time, and then the consumer pulls 2,000 items each time for processing to prevent request peaks. A large number of requests are sent directly to MySQL causing the system to crash.
    insert image description here

2. Features of RabbitMQ

RabbitMQ is an open source message middleware developed in Erlang language that implements AMQP (Advanced Message Queuing Protocol). First of all, we need to know some characteristics of RabbitMQ, which can be found on the official website:

  • reliability. Support for persistence, transmission confirmation, release confirmation, etc. ensure the reliability of MQ.
  • Flexible message distribution strategy. This should be a major feature of RabbitMQ. The message is routed by the Exchange (switch) before the message enters the MQ. Message distribution strategies include: simple mode, work queue mode, publish-subscribe mode, routing mode, and wildcard mode.
  • Clustering is supported. Multiple RabbitMQ servers can form a cluster to form a logical Broker.
  • Various agreements. RabbitMQ supports a variety of message queuing protocols, such as STOMP, MQTT and so on.
  • Supports multiple language clients. RabbitMQ supports almost all common programming languages, including Java, .NET, Ruby, etc.
  • Visual management interface. RabbitMQ provides an easy-to-use user interface that enables users to monitor and manage message brokers.
  • Plug-in mechanism. RabbitMQ provides many plug-ins, which can be extended by plug-ins, or you can write your own plug-ins.

3. Download and install RabbitMQ

Here I use the Linux environment to install:
CentOS7.9, erlang-22.3-1.el7.x86_64.rpm, rabbitmq-server-3.8.8-1.el7.noarch.rpm.
The download from the official website is too slow. Here I paste the rpm package directly. You can go to my network disk to download it.
Link: https://pan.baidu.com/s/1UiQyYu7ZaJouXsVToFvGIA
Extraction code: wmlg

3.1. Enter the centos virtual machine, enter the opt folder and upload the two npm packages you just downloaded

insert image description here

3.2. Enter the opt directory cd /opt, install erlang and rabbitmq, and execute the following commands in order.

rpm -ivh erlang-22.3-1.el7.x86_64.rpm
yum install socat -y
rpm -ivh rabbitmq-server-3.8.8-1.el7.noarch.rpm

Set the rabbitmq service to be automatically started at the next boot

chkconfig rabbitmq-server on

3.3, after that, you can start the rabbitmq command, and you can view its status

/sbin/service rabbitmq-server start
/sbin/service rabbitmq-server status

At this point we need to close the service we just started.

 /sbin/service rabbitmq-server stop

3.4. Open the rabbitmq graphical management interface

rabbitmq-plugins enable rabbitmq_management

If you encounter the following problems, when creating a virtual machine to install centos, we set our own network IP and host name, so it is no longer the default.
insert image description here
We need to view the hostname of the current session through hostname. Another way is to view the static hostname through hostnamectl status.
Modify
insert image description here
the hosts file

vi /etc/hosts

insert image description here

3.5. Restart the rabbitmq service, and then you can access it, the ip address plus the default port number;

The first time you visit and find that you can’t access, the problem is that you have not turned off the firewall;

turn off firewall

systemctl stop firewalld

Then I found out that I can access it! Default username=guest, password=guest.
insert image description here
Log in or can't log in! At this point we need to create a new user and give the user super administrator privileges.
Execute in order

rabbitmqctl list_users  //查看用户列表
rabbitmqctl add_user gyf 20020702  //设置一个新用户
rabbitmqctl set_user_tags gyf administrator  //设置超级管理员
rabbitmqctl set_permissions -p "/" gyf ".*" ".*" ".*"  //设置所有读写删改的权限

3.6. Log in with the user name and password you set, and you're done!

insert image description here

4. Study Notes (Silicon Valley)

Too many study notes! Put it on the Baidu network disk for friends, and friends who need it can get it by themselves.
Link: https://pan.baidu.com/s/1BdzfPiGEFW0ttMOjXZleSg
Extraction code: 756m

5. Summary

Delay queues are very useful in scenarios that require delayed processing. Using RabbitMQ to implement delay queues can make good use of the characteristics of RabbitMQ, such as: reliable sending of messages, reliable delivery of messages, and dead letter queues to ensure that messages are consumed at least once And messages that are not processed correctly are not discarded. In addition, through the characteristics of the RabbitMQ cluster, the single point of failure problem can be solved very well, and the delay queue will not be unavailable or the message will be lost due to the failure of a single node.

Of course, there are many other options for delay queues, such as using Java's DelayQueue, using Redis' zset, using Quartz or using kafka's time wheel. These methods have their own characteristics, depending on the applicable scenario.
come on! Programmer

Guess you like

Origin blog.csdn.net/lj20020302/article/details/130088599