Install a .rabbitmq
Description: erlang and rabbitmq versions need to match, you can view the official website matching relationship
1. Install erlang environment
yum install erlang
erlang -version to see if the installation was successful
2. Install rabbitmq
yum install rabbitmq-server
4. Set the boot from the start
chkconfig rabbitmq-server on
5. Set Profile
cd /etc/rabbitmq
cp /usr/share/doc/rabbitmq-server-3.4.1/rabbitmq.config.example /etc/rabbitmq/
mv rabbitmq.config.example rabbitmq.config
Configurations to the configuration example and rename rabbitmq
6. open the configuration file remote access
we /etc/rabbitmq/rabbitmq.config
The open configuration {loopback_users, []}, remove the end comma
7. Turn on the web interface management tool
rabbitmq-plugins enable rabbitmq_management
8. firewall port 15672 open
Or turn off the firewall
Permanently open port: firewall-cmd --permanent --add-port = 15672 / tcp
Reload open ports: firewall-cmd --reload
Check the status of: firewall-cmd --state
View open ports: firewall-cmd --list-ports
centos7 used systemctl firewall management
# Systemctl start firewalld # start,
# Systemctl enable firewalld # boot
# Systemctl stop firewalld # close
# Systemctl disable firewalld # cancel boot
9. commonly used commands
//start up
service rabbitmq-server start
// Check status
service rabbitmq-server status
//shut down
service rabbitmq-server stop
II. Create a user
1. Log Management page
http://101ycy.com:15672/ guest guest
2.admin tab add admin users, roles for the administrator
3. Role Type
Super Administrator: administrator, can log management console to view all the information on the user, the policy (policy) operate
Monitoring by: monitoring, management console can log in to see mq node information (number of processes, memory usage, disk usage, etc.)
Policy makers: policymaker, you can log management console for policy management, but can not view mq node information
General manager: management, can only login management console, can not see the node information, the policy can not be managed
Other: Can not log management console, often it is the producers and consumers
III. Create a virtual host
1. Definition: the equivalent of a library database
2. meaning: a virtual host holds a group of switches, queues and bindings, the user can do right controls the particle size of the virtual host in the rabbitmq
IV. Work six models introduced
1. Simple Queue
Switch is not specified, sent directly to the queue
2. Work Queue
Basic with simple queue, multiple queues consumer spending, the default polling distribution, you can set basicQos (perfetch = 1), consumer manual answer ack, will send a message, the process can ensure faster we receive more news
3. routing mode (switch to direct the direction switch)
Switches and to bind the queue, and sets routing keys routing key
Message to the carrying direction switch routing keys and will be delivered to the queue corresponding
4. publish subscribe model / broadcast mode (switch to switch fanout sector)
And a plurality of switch queues Binding
The switch will send a message to deliver to all queues bound
The wildcard / theme (topic switch to switch)
Similar routing mode, but the routing keys can contain wildcards
# Routing key matches one or more words, * matches a word, e.g. hello.word, hello. *, Hello. #
Five .rabbitmq usage scenarios
1. asynchronous processing
Such as user registration, send text messages and e-mail alert; anti-fraud system calls Data Services Platform is an asynchronous call
Advantages: call without waiting for the end result
2. Application of Decoupling
The system data from the A to the B-system, with a strong dependence MQ queue can be lifted, if failure does not affect the B-system A and Messaging
3. Traffic clipping
Preventing influx of a large number of system request messages First mq, and then at a rate of consumption mq message
4. Message Distribution
The message buffer
VI. Concept Note
1.broker: Message Queuing service entity
2.exchange: message switches, the message specified rule, the relationship between the process and the message queue, the queue can be bound may be bound switch
3.queue: queue, the message into the queue
4.binding: bind, bind by the switches and queue routing rules
5.routing key: routing keys, switches the message delivery according to this
6.vhost: virtual news servers, completely isolated vhost, switches, and can not be shared between different queues vhost, is mainly used to divide different business modules, access control can be done
7.producer: producer, posted a message
8.consumer: consumer acceptance message
9.channel: channel, in order to open the channel of communication, a channel assignment on behalf of a session, is a virtual connection on a real tcp
Use VII. Died switch
Consumers through basic.reject refused or undeliverable will be placed in the queue here for troubleshooting news
VIII. Send message acknowledgment
confirm (confirm callback) return (failure callback) / callbak
1. queues and to switch: performing ack = true
2. Switch error, correct queue: the implementation of ack = false
3. Switch right, I was wrong queue: a failure to perform execution ack = true
4. switches and queues are wrong: performing ack = false
IX. Reliable Message Delivery
Two programs: the following figure, the picture from the network
The message persistence, performance almost
Message delivery delay, do the second check, the RPC fails to re-send the message, but the message delay delivery of messages can fail, just more than a layer of protection
In addition some of the ways to add:
One is the use of transaction mechanism rabbitmq producers set to open affairs, and notes on sending transactional method, the rollback exception occurs, each submission will block waiting for service processing returns result, large performance impact is generally not used
1. configuration
Persistence configuration: switches, queues and persistent messages are set to
Normal switch configuration: the theme or routing mode
Backup switch configuration: broadcast mode (this configuration without routing Key), and binding two queues, queues and alarm undeliverable message queue, alert queue is used to send e-mail, text messages timely alarm
Binding backup switch: normal switch configuration alternate-exchange parameter specifies the name of the backup switch can bind
Trigger conditions: when the message queue is not properly delivered to the switch of the normal, will send messages to the backup exchange
Backup switch also receive: At this point triggers confirmcallback and returncallback, you need to enable
Confirmcallback not reach the switch trigger is false, can not reach the queue trigger returncallback
Process:
When posting switch, the write msg id and redis, if the write fails mongodb delivery switch according to the msg id read redis confirm the recording as a message delivery failure, then the timing task scan redelivery, the sign of successful successful
If forwarded to the queue fails, the message is written mongo, ibid.
2. Description simple and reliable delivery: normal delivery switch, if it fails to deliver the backup switch, or if it fails to confirm the return messages to the callback in Mongo, redelivery scan and update the status timer
3. Reliable consumption
Consumer actuates the manual answer mode, the processing is successful basicAck, two parameters, a unique identifier, all other disposable ack message less than all of the unique identification
And fails basicReject requeue = false, the process proceeds to the switch if the dead letter badmail switch, two parameters, a unique identifier, whether the second re-placed in the queue
Badmail switch configuration and dead letter queue:
The producer can be configured
Illustrated as follows: from https://blog.csdn.net/Weixiaohuai/article/details/94760975
Ten .rabbitmq cluster architecture
1. standby mode
主节点提供读写,备份节点不提供读写,在主节点产生故障或宕机时,切换到备用节点,继续提供读写服务,相互转换.
场景:并发和数据量不高情况下,也称之为warren(兔子窝)模式
2.远程模式:
多活模式,简称shovel模式,把消息进行不同数据中心的复制工作,我们可以跨地域的让两个mq集群互联,用的不多,早期的集群
3.镜像模式
mirror镜像模式,保证数据100%数据不丢失,实际工作中用的最多的,搭建简单
100%数据可靠性解决方案一般是3节点
keepalived如何配置公网IP
脑列问题
4.多活模式
依赖federation插件
下游从上游主动拉取消息