Rabbit MQ是一个通用的消息中间件,支持AMQP,STOMP,MQTT等多种协议
安装#
在OSX下可以使用如下命令来安装 rabbitmq
brew install rabbitmq
基本命令#
ls -al ~/rabbitmq/3.7.14/sbin/total 1104drwxr-xr-x 10 jet admin 320 May 19 14:35 .drwxr-xr-x 37 jet wheel 1184 May 19 14:37 ..-r-xr-xr-x 1 jet admin 468026 Mar 29 05:47 cuttlefish-r-xr-xr-x 1 jet admin 2153 May 19 14:35 rabbitmq-defaults-r-xr-xr-x 1 jet admin 1245 Mar 29 05:47 rabbitmq-diagnostics-r-xr-xr-x 1 jet admin 16069 May 19 14:35 rabbitmq-env-r-xr-xr-x 1 jet admin 1241 Mar 29 05:47 rabbitmq-plugins # manage rabbitmq plugins-r-xr-xr-x 1 jet admin 16467 Mar 29 05:47 rabbitmq-server-r-xr-xr-x 1 jet admin 40446 Mar 29 05:47 rabbitmqadmin-r-xr-xr-x 1 jet admin 1236 Mar 29 05:47 rabbitmqctl # rabbitmq controller command line
- 启动rabbitmq
rabbitmq-server -detached #detached参数可以让rabbitmq以守护进程的方式在后台运行
启动之后可以通过15271端口进行查看
停止rabbitmqrabbitmqctl shutdown
查看rabbitmq状态rabbitmqctl statusStatus of node rabbit@localhost ...[{pid,25472}, {running_applications, [{rabbitmq_stomp,"RabbitMQ STOMP plugin","3.7.14"}, {rabbitmq_amqp1_0,"AMQP 1.0 support for RabbitMQ","3.7.14"}, {rabbitmq_management,"RabbitMQ Management Console","3.7.14"}, {rabbitmq_management_agent,"RabbitMQ Management Agent","3.7.14"}, {rabbitmq_mqtt,"RabbitMQ MQTT Adapter","3.7.14"}, {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.7.14"}, {rabbit,"RabbitMQ","3.7.14"}, {amqp_client,"RabbitMQ AMQP Client","3.7.14"}, ...... {listeners, [{clustering,25672,"::"}, {amqp,5672,"127.0.0.1"}, {mqtt,1883,"::"}, {http,15672,"::"}, {stomp,61613,"::"}]}, }]
- 配置文件 rabbitmq 的配置文件位于$RABBITMQ_HOME/etc/rabbitmq/rabbitmq.conf
Rabbitmq Plugins#
Rabbitmq 提供了很多插件,在使用插件之前可以使用enable命令启用。已经安装的插件可以通过如下命令查看
rabbitmq-plugins listListing plugins with pattern ".*" ...WARNING - plugins currently enabled but missing: rabbitmq_management_visualiser Configured: E = explicitly enabled; e = implicitly enabled | Status: * = running on rabbit@localhost |/[E*] rabbitmq_amqp1_0 3.7.14[ ] rabbitmq_auth_backend_cache 3.7.14[ ] rabbitmq_auth_backend_http 3.7.14[ ] rabbitmq_auth_backend_ldap 3.7.14[ ] rabbitmq_auth_mechanism_ssl 3.7.14[ ] rabbitmq_consistent_hash_exchange 3.7.14......[ ] rabbitmq_tracing 3.7.14[ ] rabbitmq_trust_store 3.7.14[e*] rabbitmq_web_dispatch 3.7.14[ ] rabbitmq_web_mqtt 3.7.14[ ] rabbitmq_web_mqtt_examples 3.7.14[ ] rabbitmq_web_stomp 3.7.14[ ] rabbitmq_web_stomp_examples 3.7.14
启用ui管理工具
rabbitmq-plugins enable rabbitmq_management
禁用
rabbitmq-plugins disable rabbitmq_management
启停插件无需重启rabbitmq即可自动生效
Rabbitmq 消息#
Rabbitmq 包括producer, exchange, consumer三部分。
- producer: 生产者,负责生产消息
- consumer: 消费者,负责消费监听到的消息
- exchange: 负责路由消息,消息交换 其中exchange包括以下四种类型: