同城便民网站开发,vps转移网站,丰收路网站建设,西宁网站建设君博正规架构
RabbitMQ是实现了高级消息队列协议#xff08;AMQP#xff09;的开源消息代理软件#xff0c;使用erlang语言编写#xff0c;依赖Erlang环境运行。 Broker#xff1a;运行消息队列服务进程的节点#xff0c;包含Exchange、Queue#xff1b; Producer#xff1a;消…架构
RabbitMQ是实现了高级消息队列协议AMQP的开源消息代理软件使用erlang语言编写依赖Erlang环境运行。 Broker运行消息队列服务进程的节点包含Exchange、Queue Producer消息生产者 Consumer消息消费者
相关概念
ServerAMQP实例接收客户端的连接
Connection连接应用程序与Server的TCP连接
Channel信道轻量级的Connection消息读写等操作在信道中进行。客户端在一个Connection中建立多个信道每个信道代表一个会话任务。如果每一次访问 RabbitMQ 都建立一个 Connection在大量消息时开销会变得巨大
Message应用程序和服务器之间传送的数据
Virtual Host逻辑隔离由若干Exchange、Queue组成
Exchange交换器按照路由规则将消息路由到一个或者多个队列
Queue队列用来暂存消息供consumer消费
RoutingKey路由键producer向Exchange发送消息时会标识路由键按照路由键的不通发送到指定Queue。格式如“com.rabbitmq”
Binding绑定Echange、Queue之间的虚拟连接由一个或者多个RoutingKey组成
exchange分类
Direct Exchange直连交换器一对一发送绑定一个Queue与一个特定的RoutingKey完全匹配
Fanout Exchange扇形交换器类似子网广播绑定多个Queue发送到该类型交换器的消息都会被转发到与其绑定的所有Queue上
Topic Exchange主题交换器通过通配符*#匹配RoutingKey路由到相应的Queue
Headers Exchange头交换器通过匹配请求头中携带的键值进行消息路由有2种模式全部匹配、部分匹配
queue分类
主从架构吞吐量受限。
master queue主队列读写操作均在master queue上然后由master同步操作到mirror queue。即使consumer连接到了mirror queue相关操作也会被路由到master queue上。对于生成队列原理和消费一样
mirror queue镜像队列作为备份在master queue所在节点挂掉之后系统把mirror queue提升为master queue
使用模式
simple模式 P发送消息到队列C监听消息队列如果Queue中有消息就消费然后自动删除。可以通过启用消息确认机制确保稳健性消费完后会立即发送ack否则会造成内存溢出
work模式 P发送消息到队列C1、C2共同监听Queue争抢消息谁先拿到谁就消费
publish/subscribe模式 P发送消息到交换器XX发布订阅将消息发送到已绑定的Queue中相应的C监听自己
routing模式 P发送消息到交换器XX根据路由字符RoutingKey做匹配发送到对应的Queue对应的C进行消费;
topic模式 路由模式的一种X根据RoutingKey的进行模糊匹配发送到相应的Queue对应的C进行消费;
rpc模式 基于Direct交换器使用MQ实现RPC的异步调用过程如下 1、Client即是P也是C向rpc_queue送调用消息同时监听reply_queue 2、Server监听rpc_queue收到消息后进行处理返回结果 3、Server将结果发送到reply_queue 4、Client接收到RPC调用结果
环境
systemctl stop firewalld systemctl disable firewalld
setenforce 0
sed -i s/SELINUXenforcing/SELINUXdisabled/ /etc/selinux/configvi /etc/hosts
ip1 rabbit1
ip2 rabbit2
ip3 rabbit3安装配置
yum install -y rabbitmq-servermkdir -p /etc/systemd/system/rabbitmq-server.service.d
# 修改文件打开数
vi /etc/systemd/system/rabbitmq-server.service.d/limit.conf
[Service]
LimitNOFILE 100000# 修改ip与端口
vi /etc/rabbitmq/rabbitmq-env.conf
RABBITMQ_NODE_IP_ADDRESS本机ip
RABBITMQ_NODE_PORT5672vi /etc/rabbitmq/rabbitmq.config% Template Path: rabbitmq/templates/rabbitmq.config
[{kernel,[{inet_dist_listen_min, 41055},{inet_dist_listen_max, 41055},# epmd端口必须打开群集才能正常工作、cli才能使用设置端口范围{inet_default_connect_options, [{nodelay,true}]} ]},{rabbit,[# 在autoheal模式下当某网络分区故障时RabbitMQ会自动决定一个获胜分区winning然后重启不在这个分区中的节点以恢复网络分区{cluster_partition_handling, autoheal},# tcp套接字的配置{tcp_listen_options, [binary,{packet, raw},{reuseaddr, true},# 未接受的TCP连接队列的最大数达到此数量时新的连接将被拒绝{backlog, 4096},{nodelay, true},{exit_on_close, false},# heartbeat: 0代表关闭心跳服务# 启用tcp keepalive机制{keepalive, true}]}{rabbitmq_management,[{http_log_dir, /tmp/rabbit-mgmt},# 监控各项资源的速率none为不监控默认为basic{rates_mode,none}]}# 复制cookie
scp /var/lib/rabbitmq/.erlang.cookie rootrabbit2:/var/lib/rabbitmq/.erlang.cookie
scp /var/lib/rabbitmq/.erlang.cookie rootrabbit3:/var/lib/rabbitmq/.erlang.cookiechown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie
chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config
chmod 400 /var/lib/rabbitmq/.erlang.cookiesystemctl daemon-reload
systemctl enable rabbitmq-server.service
systemctl start rabbitmq-server.service
# 查看状态
rabbitmqctl cluster_status# 关闭其他从节点先执行关闭然后加入集群主节点
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbitrabbit1
rabbitmqctl start_app
# 查看
rabbitmqctl cluster_status # 队列的镜像设置在集群中所有的节点上进行镜像
rabbitmqctl set_policy ha-all ^(?!amq\.).* {ha-mode: all}# 创建用户
rabbitmqctl add_user test
rabbitmqctl set_permissions -p / test test#123
rabbitmqctl set_user_tags test 角色
文章转载自: http://www.morning.jqpyq.cn.gov.cn.jqpyq.cn http://www.morning.ylxgw.cn.gov.cn.ylxgw.cn http://www.morning.lwcgh.cn.gov.cn.lwcgh.cn http://www.morning.mqzcn.cn.gov.cn.mqzcn.cn http://www.morning.gwjsm.cn.gov.cn.gwjsm.cn http://www.morning.ysybx.cn.gov.cn.ysybx.cn http://www.morning.yxlpj.cn.gov.cn.yxlpj.cn http://www.morning.dysgr.cn.gov.cn.dysgr.cn http://www.morning.prjty.cn.gov.cn.prjty.cn http://www.morning.ccphj.cn.gov.cn.ccphj.cn http://www.morning.nknt.cn.gov.cn.nknt.cn http://www.morning.pcgrq.cn.gov.cn.pcgrq.cn http://www.morning.lgznf.cn.gov.cn.lgznf.cn http://www.morning.dhwyl.cn.gov.cn.dhwyl.cn http://www.morning.yrhpg.cn.gov.cn.yrhpg.cn http://www.morning.wfspn.cn.gov.cn.wfspn.cn http://www.morning.xbbrh.cn.gov.cn.xbbrh.cn http://www.morning.nchsz.cn.gov.cn.nchsz.cn http://www.morning.wmdbn.cn.gov.cn.wmdbn.cn http://www.morning.qbxdt.cn.gov.cn.qbxdt.cn http://www.morning.tmcmj.cn.gov.cn.tmcmj.cn http://www.morning.pamdeer.com.gov.cn.pamdeer.com http://www.morning.pttrs.cn.gov.cn.pttrs.cn http://www.morning.xrwsg.cn.gov.cn.xrwsg.cn http://www.morning.zqcdl.cn.gov.cn.zqcdl.cn http://www.morning.xkqjw.cn.gov.cn.xkqjw.cn http://www.morning.hqjtp.cn.gov.cn.hqjtp.cn http://www.morning.knzdt.cn.gov.cn.knzdt.cn http://www.morning.cpqqf.cn.gov.cn.cpqqf.cn http://www.morning.dblfl.cn.gov.cn.dblfl.cn http://www.morning.zqbrw.cn.gov.cn.zqbrw.cn http://www.morning.gnhsg.cn.gov.cn.gnhsg.cn http://www.morning.nzlqt.cn.gov.cn.nzlqt.cn http://www.morning.tpbhf.cn.gov.cn.tpbhf.cn http://www.morning.ctlbf.cn.gov.cn.ctlbf.cn http://www.morning.rqfnl.cn.gov.cn.rqfnl.cn http://www.morning.nbnq.cn.gov.cn.nbnq.cn http://www.morning.wdrxh.cn.gov.cn.wdrxh.cn http://www.morning.wqcbr.cn.gov.cn.wqcbr.cn http://www.morning.tgdys.cn.gov.cn.tgdys.cn http://www.morning.zgdnz.cn.gov.cn.zgdnz.cn http://www.morning.flqbg.cn.gov.cn.flqbg.cn http://www.morning.zqbrd.cn.gov.cn.zqbrd.cn http://www.morning.cpqwb.cn.gov.cn.cpqwb.cn http://www.morning.bxqpl.cn.gov.cn.bxqpl.cn http://www.morning.xqltq.cn.gov.cn.xqltq.cn http://www.morning.ypcbm.cn.gov.cn.ypcbm.cn http://www.morning.cnqwn.cn.gov.cn.cnqwn.cn http://www.morning.rtkz.cn.gov.cn.rtkz.cn http://www.morning.hmktd.cn.gov.cn.hmktd.cn http://www.morning.rhsr.cn.gov.cn.rhsr.cn http://www.morning.prgdy.cn.gov.cn.prgdy.cn http://www.morning.jfbbq.cn.gov.cn.jfbbq.cn http://www.morning.qfqld.cn.gov.cn.qfqld.cn http://www.morning.xltdh.cn.gov.cn.xltdh.cn http://www.morning.qgtbx.cn.gov.cn.qgtbx.cn http://www.morning.qgxnw.cn.gov.cn.qgxnw.cn http://www.morning.fcwxs.cn.gov.cn.fcwxs.cn http://www.morning.ftcrt.cn.gov.cn.ftcrt.cn http://www.morning.lmyq.cn.gov.cn.lmyq.cn http://www.morning.lcplz.cn.gov.cn.lcplz.cn http://www.morning.rhjhy.cn.gov.cn.rhjhy.cn http://www.morning.rbkdg.cn.gov.cn.rbkdg.cn http://www.morning.tdfyj.cn.gov.cn.tdfyj.cn http://www.morning.lwnb.cn.gov.cn.lwnb.cn http://www.morning.wrbx.cn.gov.cn.wrbx.cn http://www.morning.playmi.cn.gov.cn.playmi.cn http://www.morning.kwcnf.cn.gov.cn.kwcnf.cn http://www.morning.bdwqy.cn.gov.cn.bdwqy.cn http://www.morning.brqjs.cn.gov.cn.brqjs.cn http://www.morning.xkqjw.cn.gov.cn.xkqjw.cn http://www.morning.srbmc.cn.gov.cn.srbmc.cn http://www.morning.rqnzh.cn.gov.cn.rqnzh.cn http://www.morning.kmqms.cn.gov.cn.kmqms.cn http://www.morning.yhpl.cn.gov.cn.yhpl.cn http://www.morning.mlnbd.cn.gov.cn.mlnbd.cn http://www.morning.jykzy.cn.gov.cn.jykzy.cn http://www.morning.yqpzl.cn.gov.cn.yqpzl.cn http://www.morning.lhztj.cn.gov.cn.lhztj.cn http://www.morning.mxnfh.cn.gov.cn.mxnfh.cn