降低了服务器的压力
加快了服务器的响应速度,优化了用户体验
降低了服务器之间的耦合
处理业务的时候,升级系统可以停用处理消息的服务器
架构更加复杂,会依赖于队列(容器)
特点:使用频繁,上手快,易学
性能高,主要用于大型系统架构
rpm -qa | grep erlang
yum list | grep erlang yun -y remove erlang-* rm -rf /usr/lib64/erlang
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
yum install erlang
erl
rpm -qa | grep rabbitmq
yum list | grep rabbitmq yum -y remove rabbitmq-server.noarch
rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey rpm --import https://packagecloud.io/gpg.key
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.5/rabbitmq-server-3.8.5-1.el8.noarch.rpm
rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
yum -y install epel-release yum -y install socat
rpm -ivh rabbitmq-server-3.8.5-1.el8.noarch.rpm
rabbitmq-plugins enable rabbitmq_management
rabbitmq可视化端口:15672
rabbitmq链接端口:5672
http://宿主机IP:15672/#/queues
rabbitmqctl add_user richard richard
rabbitmqctl set_user_tags richard administrator
systemctl start rabbitmq-server
firewall-cmd --add-port=15672/tcp --permanent firewall-cmd --add-port=5672/tcp --permanent #重启防火墙 firewall-cmd --reload
docker search rabbitmq
docker pull rabbitmq
1.第一个映射端口是可视化端口号
2.第二个映射端口是链接端口号
docker run -d -name Yp_rabbitmq -p 15677:15672 -p 5677:5672 镜像ID
docker ps -a docker exec -it 容器ID bash rabbitmq-plugins enable rabbitmq_management
docker ps -a docker restart 容器ID
A.地址: http://宿主机的IP:第三步指定可视化端口号
B.默认账号:guest
C.默认密码:guest
引入帮助类库
ConnectionFactory factory= new ConnectionFactory(); //创建链接工厂 factory.HostName = "192.168.1.21"; factory.UserName = "yangpeng"; factory.Password = "yangpeng"; factory.Port = 5672; //默认端口号是:5672
ConnectionFactory factory= new ConnectionFactory(); //创建链接工厂 factory.HostName = "192.168.1.21"; factory.UserName = "yangpeng"; factory.Password = "yangpeng"; factory.Port = 5672; //默认端口号是:5672 using (IConnection connection = factory.CreateConnection()) //创建链接 { }
ConnectionFactory factory= new ConnectionFactory(); //创建链接工厂 factory.HostName = "192.168.1.21"; factory.UserName = "yangpeng"; factory.Password = "yangpeng"; factory.Port = 5672; //默认端口号是:5672 using (IConnection connection = factory.CreateConnection()) //基于创建链接 { using (IModel channel = connection.CreateModel()) //基于链接创建信道 { } }
ConnectionFactory factory= new ConnectionFactory(); //创建链接工厂 factory.HostName = "192.168.1.21"; factory.UserName = "yangpeng"; factory.Password = "yangpeng"; factory.Port = 5672; //默认端口号是:5672 using (IConnection connection = factory.CreateConnection()) { using (IModel channel = connection.CreateModel()) { //创建队列 channel.QueueDeclare(queue: "OnlyProducerMessage", durable: true, exclusive: false, autoDelete: false, arguments: null); //创建交换机 channel.ExchangeDeclare(exchange: "OnlyProducerMessageExChange", type: ExchangeType.Direct, durable: true, autoDelete: false, arguments: null); //将队列和交换机绑定 channel.QueueBind(queue: "OnlyProducerMessage", exchange: "OnlyProducerMessageExChange", routingKey: String.Empty, arguments: null); } }
ConnectionFactory factory= new ConnectionFactory(); //创建链接工厂 factory.HostName = "192.168.1.21"; factory.UserName = "yangpeng"; factory.Password = "yangpeng"; factory.Port = 5672; //默认端口号是:5672 using (IConnection connection = factory.CreateConnection()) { using (IModel channel = connection.CreateModel()) { //创建队列 channel.QueueDeclare(queue: "OnlyProducerMessage", durable: true, exclusive: false, autoDelete: false, arguments: null); //创建交换机 channel.ExchangeDeclare(exchange: "OnlyProducerMessageExChange", type: ExchangeType.Direct, durable: true, autoDelete: false, arguments: null); //将队列和交换机绑定 channel.QueueBind(queue: "OnlyProducerMessage", exchange: "OnlyProducerMessageExChange", routingKey: String.Empty, arguments: null); Console.ForegroundColor=ConsoleColor.Red; Console.WriteLine("生产者已经准备就绪"); int i = 1; while (i <= 100) { string message = $"生成者发送第{i}条消息;"; byte[] body=Encoding.UTF8.GetBytes(message); channel.BasicPublish(exchange: "OnlyProducerMessageExChange", routingKey: string.Empty, basicProperties: null, body: body); Console.WriteLine($"消息已发送{i}条"); i++; Thread.Sleep(500); } } }
ConnectionFactory factory= new ConnectionFactory(); //创建链接工厂 factory.HostName = "192.168.1.21"; factory.UserName = "yangpeng"; factory.Password = "yangpeng"; factory.Port = 5672; //默认端口号是:5672
ConnectionFactory factory= new ConnectionFactory(); //创建链接工厂 factory.HostName = "192.168.1.21"; factory.UserName = "yangpeng"; factory.Password = "yangpeng"; factory.Port = 5672; //默认端口号是:5672 using (IConnection connection = factory.CreateConnection()) //创建链接 { }
ConnectionFactory factory= new ConnectionFactory(); //创建链接工厂 factory.HostName = "192.168.1.21"; factory.UserName = "yangpeng"; factory.Password = "yangpeng"; factory.Port = 5672; //默认端口号是:5672 using (IConnection connection = factory.CreateConnection()) //基于创建链接 { using (IModel channel = connection.CreateModel()) //基于链接创建信道 { } }
Stats in management UI are disabled on this node
docker exec -it 容器ID bash cd /etc/rabbitmq/conf.d/ echo management_agent.disable_metrics_collector = false > management_agent.disable_metrics_collector.conf
var factory = new ConnectionFactory(); factory.AutomaticRecoveryEnabled = true; //设置端口后自动恢复连接属性即可