RabbitMQ
introduce
RabbitMQ: 基于AMQP协议标准,采用 Erlang 实现的工业级的消息队列(MQ)服务器 AMQP 0-9-1 (Advanced Message Queuing Protocol) 中间件(允许不同程序协同工作)
concept
路由不会发生争抢消息的情况(和kafka不同消费者使用同样的group会争抢消息的情况不同)
- exchange - route rules (四种类型)
- Direct(routing keys, a message attribute) (default), 比如amq.direct
- Fanout(bindings) broadcast, 忽略了routing key, 绑定了所有queue。比如amq.fanout
- Topic(wildcard in bindings and routing keys) (#, *), 比如amq.topic 使用 * ,匹配一个word, 类似 Direct 使用#,匹配任意多words, 类似 Fanout
-
Headers(header attributes,key-value format),比如amq.headers 参数:durable, temporary(rabbitmq关闭时会删除), and auto delete
-
routing key address (binding key(exchange和queue绑定的参数) = routing key(exchange路由的参数)) the routing key acts like a filter. 当一条消息的routing key不匹配任何一个binding key时,消息会被丢弃
-
channels : "lightweight connections that share a single TCP connection".
-
virtual hosts 多租户系统 connections, exchanges, queues, bindings, user permissions, policies and some other things belong to virtual hosts, logical groups of entities
process
消息从exchange路由到queue的依据信息: header attribute, routing key, binding key 但不同类型exchange采用不同信息
producer - route(messaging broker) - consumer
Publisher -> (publish) -> Exchange -> (routes) -> Queue -> (consumes) -> Consumer
setup
install erlang, set system environment: ERLANG_HOME
cmd 进入 rabbitmq 下面的 sbin文件夹
1.安装web页面 (localhost:15672 guest/guest, guest用户不能远程登陆))
rabbitmq-plugins.bat enable rabbitmq_management
start rabbitmq : double click rabbitmq-service.bat or rabbitmq-server.bat
2.创建用户
rabbitmqctl.bat add_user admin admin
3.设置管理员
rabbitmqctl.bat set_user_tags admin administrator
4.设置权限
rabbitmqctl.bat set_permissions -p / admin ".*" ".*" ".*"
5.other
rabbitmqctl.bat list_users