Rabbitmq of message queue

Hane 2021-01-14 14:50:07
rabbitmq message queue


Mind mapping

RabbitMQ

1. Overview of message middleware

1.1. What is message middleware

MQ Its full name is Message Queue, Message queuing is a method of communication between an application and an application .

  • Why use MQ In the project , Some time-consuming operations without immediate return can be extracted , Conduct Asynchronous processing , This asynchronous processing method greatly saves the server's request response time , thus Improve System Of throughput .
  • Message queuing in development usually has the following application scenarios : 1、 Mission asynchronous Handle The message queue notifies the message receiver of asynchronous processing of the long-time operation that does not need synchronous processing . Improved application response time . 2、 Applications Decoupling MQ It's like an intermediary , The manufacturer passes through MQ Interact with consumers , It decouples applications . 3、 Peak shaving and valley filling Such as order system , When you place an order, you will write data to the database . But the database can only support every second 1000 Left and right concurrent writes , No matter how high the concurrency is, it's easy to Downtime ( The computer doesn't work properly ). When the peak period is low, the concurrency is also 100 Multiple , But in the rush hour , Concurrency will suddenly surge to 5000 above , The database must be stuck at this time .

The message is MQ It's saved , Then the system can consume according to its own consumption ability , Every second, for example. 1000 Data , This slowly writes to the database , So you don't get stuck in the database .

But it did MQ after , Limit the speed of consuming messages to 1000, But in this way , The data generated during the peak period is bound to be overstocked MQ in , Gao Feng is cut It fell off . But because of the backlog , For a period of time after the peak , The rate of consumption of news will remain at 1000QPS, Until the consumption of the backlog of news , This is called “ Filling grain ”

1.2. AMQP and JMS

MQ It's a model of message communication ; Realization MQ There are roughly two main ways to do it :AMQPJMS.

1.2.1. AMQP

AMQP It's a protocol , More precisely, it's a kind of binary wire-level protocol( Link agreement ). This is the sum of JMS The essential difference ,AMQP Not from API Layer to define , But directly define the data format of network exchange .

1.2.2. JMS

JMS namely Java Message service (JavaMessage Service) Application program interface , It's a Java About message-oriented middleware in the platform (MOM) Of API, Used between two applications , Or send a message in a distributed system , Asynchronous communication .

1.2.3. AMQP And JMS difference

  • JMS It defines a unified interface , To unify message operations ;AMQP It's about Unifying the format of data interaction through protocols
  • JMS It limits the use of Java Language ;AMQP It's just an agreement , There is no way of implementation , So it's Cross lingual .
  • JMS Two message modes are specified ; and AMQP The message pattern is richer

1.3. Message queuing products

The common message queues on the market are as follows :

  • ActiveMQ: be based on JMS
  • ZeroMQ: be based on C Language Development
  • RabbitMQ: be based on AMQP agreement ,erlang Language development , Good stability
  • RocketMQ: be based on JMS, Alibaba products
  • Kafka: similar MQ Products ; Distributed messaging system , High throughput

1.4. RabbitMQ

RabbitMQ By erlang Language development , be based on AMQPAdvanced Message Queue Advanced message queue protocol ) Protocol implementation of message queue , It's a way of communicating between applications , Message queue is widely used in distributed system development .

RabbitMQ Official address :http://www.rabbitmq.com/

RabbitMQ Provides 6 Patterns :

  1. Simple mode
  2. work Pattern
  3. Publish/Subscribe Publish and subscribe mode
  4. Routing Routing mode
  5. Topics Theme mode
  6. RPC Remote call mode ( The remote invocation , Not so much MQ; No introduction for the moment );

Introduction to the corresponding mode of the official website :https://www.rabbitmq.com/getstarted.html

2. Installation and configuration RabbitMQ

Be careful : Please use the CentOS-7-x86_64-DVD-1810.iso Install virtual machine . Here is Tencent cloud server

1. Install dependent environment

Online installation depends on the environment :

yum install build-essential openssl openssl-devel unixODBC unixODBC-devel make gcc gcc-c++ kernel-devel m4 ncurses-devel tk tc xz

2. install Erlang

Upload put -r D:/..

  • erlang-18.3-1.el7.centos.x86_64.rpm
  • socat-1.7.3.2-5.el7.lux.x86_64.rpm
  • rabbitmq-server-3.6.5-1.noarch.rpm
# install erlang
[root@VM_0_16_centos rabbitmq]# rpm -ivh erlang-18.3-1.el7.centos.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:erlang-18.3-1.el7.centos ################################# [100%]
[root@VM_0_16_centos rabbitmq]#

If the following error occurs

explain gblic Outdated Version . We can look at the current machine gblic edition

strings /lib64/libc.so.6 | grep GLIBC

The current highest version 2.12, need 2.15. So we need to upgrade glibc

Use yum Update installation depends on

sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make -y

download rpm package

wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-utils-2.17-55.el6.x86_64.rpm &
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-static-2.17-55.el6.x86_64.rpm &
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-2.17-55.el6.x86_64.rpm &
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-common-2.17-55.el6.x86_64.rpm &
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-devel-2.17-55.el6.x86_64.rpm &
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-headers-2.17-55.el6.x86_64.rpm &
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/nscd-2.17-55.el6.x86_64.rpm &

install rpm package

sudo rpm -Uvh *-2.17-55.el6.x86_64.rpm --force --nodeps

Check again after installation glibc edition , Find out glibc The version has arrived 2.17 了

strings /lib64/libc.so.6 | grep GLIBC

3. install RabbitMQ

# install socat
[root@VM_0_16_centos rabbitmq]# rpm -ivh socat-1.7.3.2-1.1.el7.x86_64.rpm
warning: socat-1.7.3.2-1.1.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 87e360b8: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:socat-1.7.3.2-1.1.el7 ################################# [100%]
[root@VM_0_16_centos rabbitmq]#
# install rabbitmq-server
[root@VM_0_16_centos rabbitmq]# rpm -ivh rabbitmq-server-3.6.5-1.noarch.rpm
warning: rabbitmq-server-3.6.5-1.noarch.rpm: Header V4 RSA/SHA1 Signature, key ID 6026dfca: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:rabbitmq-server-3.6.5-1 ################################# [100%]
[root@VM_0_16_centos rabbitmq]#

4. Open the management interface and configuration

# Open the management interface
rabbitmq-plugins enable rabbitmq_management
# Modify default configuration information
vim /usr/lib/rabbitmq/lib/rabbitmq_server-3.6.5/ebin/rabbit.app
# For example, change the password 、 The configuration, etc. , for example :loopback_users Medium <<"guest">>, Only keep guest

5. start-up

service rabbitmq-server start # Start the service
service rabbitmq-server stop # Out of Service
service rabbitmq-server restart # Restart the service
  • Setup profile
cd /usr/share/doc/rabbitmq-server-3.6.5/
cp rabbitmq.config.example /etc/rabbitmq/rabbitmq.config

6. Configure virtual hosts and users

6.1. User roles

RabbitMQ After installation , You can visit http://ip Address :15672 ; It comes with it guest/guest Username and password ; If you need to create a custom user ; You can also log in to the management interface , Do the following :

The login page

Login successful

Add users

Role description

1、 Super administrator (administrator)

You can log in to the management console , You can view all the information , And for users , Strategy (policy) To operate .

2、 Monitor (monitoring)

You can log in to the management console , At the same time, you can view rabbitmq Information about nodes ( Number of processes , Memory usage , Disk usage, etc )

3、 Strategy maker (policymaker)

You can log in to the management console , At the same time, it can be right policy Conduct management . But you can't view the information about the node ( Part of the red box above ).

4、 General manager (management)

Only log in to the admin console , Can't see node information , You can't manage policies .

5、 other

Unable to log on to admin console , It's usually ordinary producers and consumers .

6.2. Virtual Hosts To configure

image mysql Have the concept of database, and can specify the user's permissions on the operation of database and table .RabbitMQ There's a similar privilege management ; stay RabbitMQ Virtual message server can be used in Virtual Host, Every Virtual Hosts It's equivalent to a relatively independent RabbitMQ The server , Every VirtualHost They are isolated from each other .exchange、queue、message No interworking . amount to mysql Of db.Virtual Name General with / start .

6.2.1. establish Virtual Hosts

6.2.2. Set up Virtual Hosts jurisdiction

  • solve not found problem

take /usr/share/doc/rabbitmq-server-3.6.5/rabbitmq.config.example Copy to the specified /etc/rabbitmq/rabbitmq.config, And then restart it service rabbitmq-server restart

[root@VM_0_16_centos ~]# cd /usr/share/doc/rabbitmq-server-3.6.5/
[root@VM_0_16_centos rabbitmq-server-3.6.5]# ll
total 200
-rw-r--r-- 1 root root 28945 Aug 5 2016 LICENSE
-rw-r--r-- 1 root root 11358 Aug 5 2016 LICENSE-APACHE2-ExplorerCanvas
-rw-r--r-- 1 root root 10175 Aug 5 2016 LICENSE-APL2-Rebar
-rw-r--r-- 1 root root 10851 Aug 5 2016 LICENSE-APL2-Stomp-Websocket
-rw-r--r-- 1 root root 1206 Aug 5 2016 LICENSE-BSD-base64js
-rw-r--r-- 1 root root 1304 Aug 5 2016 LICENSE-BSD-glMatrix
-rw-r--r-- 1 root root 14041 Aug 5 2016 LICENSE-EPL-OTP
-rw-r--r-- 1 root root 1087 Aug 5 2016 LICENSE-MIT-EJS10
-rw-r--r-- 1 root root 1069 Aug 5 2016 LICENSE-MIT-Flot
-rw-r--r-- 1 root root 1075 Aug 5 2016 LICENSE-MIT-jQuery164
-rw-r--r-- 1 root root 1087 Mar 31 2016 LICENSE-MIT-Mochi
-rw-r--r-- 1 root root 1087 Aug 5 2016 LICENSE-MIT-Mochiweb
-rw-r--r-- 1 root root 1076 Aug 5 2016 LICENSE-MIT-Sammy060
-rw-r--r-- 1 root root 1056 Aug 5 2016 LICENSE-MIT-SockJS
-rw-r--r-- 1 root root 16726 Aug 5 2016 LICENSE-MPL2
-rw-r--r-- 1 root root 24897 Aug 5 2016 LICENSE-MPL-RabbitMQ
-rw-r--r-- 1 root root 21023 Apr 11 2016 rabbitmq.config.example
-rw-r--r-- 1 root root 943 Mar 31 2016 README
-rw-r--r-- 1 root root 277 Mar 31 2016 set_rabbitmq_policy.sh.example
[root@VM_0_16_centos rabbitmq-server-3.6.5]# cp ./rabbitmq.config.example /etc/rabbitmq/rabbitmq.config
[root@VM_0_16_centos rabbitmq-server-3.6.5]# service rabbitmq-server restart
Restarting rabbitmq-server (via systemctl): [ OK ]
[root@VM_0_16_centos rabbitmq-server-3.6.5]#

Refresh the page and you will succeed

  • ? WeChat : 1210331079
  • ? QQ : 1210331079
  • ? mailbox : shaotongjie@gmail.com
  • ? Personal blog : https://nateshao.gitee.io perhaps https://nateshao.github.io
  • ? GitHub : https://github.com/nateshao
  • ? Gitee : https://gitee.com/nateshao
  • ? WeChat official account : Qianyu's programming time

This article is from WeChat official account. - Qianyu's programming time (gh_7adc8f5689e2)

The source and reprint of the original text are detailed in the text , If there is any infringement , Please contact the yunjia_community@tencent.com Delete .

Original publication time : 2020-09-15

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

版权声明
本文为[Hane ]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210114144734152x.html

  1. Redis basic command
  2. Summary of MySQL articles
  3. 2、 Create k8s cluster in 5 seconds
  4. data自定义属性在jQuery中的用法
  5. Linux常见解压缩
  6. Detailed explanation of HBase basic principle
  7. 1、 Why and how to learn k8s
  8. Java advanced (29) -- HashMap set
  9. java中大文件上传
  10. Weblogic 2017-3248 analysis of Java Security
  11. Kubernetes official java client 8: fluent style
  12. Explain the function of thread pool and how to use it in Java
  13. Programming software tutorial video Encyclopedia: C + + / Java / Python / assembly / easy language (with tutorial)
  14. Description of dependency problem after javacv is updated to 1.5. X and how to reduce the size of dependency package
  15. Java reflection & dynamic agent
  16. Building Apache 2.4 + php7 + mysql8 in centos7 environment
  17. Summary of Java multithreading (1)
  18. Oracle AWR report generation
  19. Four magic functions of mybatis, don't step on the pit!
  20. A 16-year-old high school student successfully transplanted Linux to iPhone and posted a detailed guide
  21. Centos7 one click installation of JDK1.8 shell script
  22. Mounting of file system in Linux (centos7)
  23. How does serverless deal with the resource supply demand of k8s in the offline scenario
  24. Detailed explanation of HBase basic principle
  25. Spring security oauth2.0 authentication and authorization 4: distributed system authentication and authorization
  26. Redis performance Part 5 redis buffer
  27. JavaScript this keyword
  28. Summary of Java multithreading (3)
  29. Sentry(v20.12.1) K8S 云原生架构探索, SENTRY FOR JAVASCRIPT 手动捕获事件基本用法
  30. Sentry(v20.12.1) K8S 云原生架构探索, SENTRY FOR JAVASCRIPT 手动捕获事件基本用法
  31. (10) Spring from the beginning to the end
  32. Summary of Java multithreading (2)
  33. Spring source notes! From the introduction to the source code, let you really understand the source code
  34. A stormy sunny day
  35. Zookeeper (curator), the implementation of distributed lock
  36. Show the sky! Tencent T4's core Java Dictionary (framework + principle + Notes + map)
  37. Spring boot project, how to gracefully replace the blank value in the interface parameter with null value?
  38. Spring boot project, how to gracefully replace the blank value in the interface parameter with null value?
  39. docker+mysql集群+读写分离+mycat管理+垂直分库+负载均衡
  40. docker+mysql集群+读写分离+mycat管理+垂直分库+负载均衡
  41. To what extent can I go out to work?
  42. Java 使用拦截器无限转发/重定向无限循环/重定向次数过多报错(StackOverflowError) 解决方案
  43. Implementation of rocketmq message sending based on JMeter
  44. How to choose the ticket grabbing app in the Spring Festival? We have measured
  45. Implementation of rocketmq message sending based on JMeter
  46. My programmer's Road: self study java
  47. My programmer's Road: self study java
  48. All in one, one article talks about the use of virtual machine VirtualBox and Linux
  49. All in one, one article talks about the use of virtual machine VirtualBox and Linux
  50. Java 使用拦截器无限转发/重定向无限循环/重定向次数过多报错(StackOverflowError) 解决方案
  51. [Java training project] Java ID number recognition system
  52. How does serverless deal with the resource supply demand of k8s in the offline scenario
  53. Detailed explanation of HBase basic principle
  54. Explain the function of thread pool and how to use it in Java
  55. Kubernetes official java client 8: fluent style
  56. 010_MySQL
  57. Vibrant special purchases for the Spring Festival tiktok section, hundreds of good things to make the year more rich flavor.
  58. 010_MySQL
  59. Of the 4 million docker images, 51% have high-risk vulnerabilities
  60. Rocketmq CPP client visual studio 2019 compilation