赞
踩
MQ(message queue),从字面意思上看,本质是个队列,FIFO 先入先出,只不过队列中存放的内容是
message 而已,还是一种跨进程的通信机制,用于上下游传递消息
流量削峰
应用解耦
异步处理
ActiveMQ
Kafka
RocketMQ
RabbitMQ
大型项目:RocketMQ
日志收集(就是跟大数据量打交道):kafka
小/中型项目:RabbitMQ
社区活跃度:
RabbitMQ > RocketMQ > kafka
消息持久化:
RabbitMQ、RocketMQ、kafka都支持持久化
高并发:
kafka = RocketMQ > RabbitMQ
吞吐量:
kafka = RocketMQ > RabbitMQ
RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件)
虚拟主机(virtual host)或(vhost)
交换机(exchange)
队列(queue)
绑定器(bind)
连接(Connection)
通道 (Channel)
# 1.拉取镜像
[root@izbp1j6sv2mtxgnuthuw6bz ~]# docker pull rabbitmq:3.8-management
# 2.查看镜像
[root@izbp1j6sv2mtxgnuthuw6bz ~]# docker images
# 3.启动
[root@izbp1j6sv2mtxgnuthuw6bz ~]# docker run -itd --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.8-management
a5ca877169d4eda31a9c404f94565c118f1cc64de2cbb398ff17a66e72c682cd
# 4.查看启动情况
[root@izbp1j6sv2mtxgnuthuw6bz ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a5ca877169d4 rabbitmq:3.8-management "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp rabbitmq
问题
# 进入rabbitmq
[root@izbp1j6sv2mtxgnuthuw6bz ~]# docker exec -it rabbitmq bash
# 启动web管理界面
root@a5ca877169d4:/# rabbitmq-plugins enable rabbitmq_management
# 创建账号 root@a5ca877169d4:/# rabbitmqctl add_user admin admin Adding user "admin" ... Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more. # 设置用户角色 root@a5ca877169d4:/# rabbitmqctl set_user_tags admin administrator Setting tags for user "admin" to [administrator] ... # 设置用户权限 # set_permissions [-p <vhostpath>] <user> <conf> <write> <read> # 用户 admin 具有/vhost1 这个 virtual host 中所有资源的配置、写、读权限 root@a5ca877169d4:/# rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*" Setting permissions for user "admin" in vhost "/" ... # 查看当前用户和角色 root@a5ca877169d4:/# rabbitmqctl list_users Listing users ... user tags admin [administrator] guest [administrator]
<!--指定 jdk 编译版本--> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>8</source> <target>8</target> </configuration> </plugin> </plugins> </build> <dependencies> <!--rabbitmq 依赖客户端--> <dependency> <groupId>com.rabbitmq</groupId> <artifactId>amqp-client</artifactId> <version>5.8.0</version> </dependency> <!--操作文件流的一个依赖--> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.6</version> </dependency> </dependencies>
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
public class Producer {
private final static String QUEUE_NAME = "hello";
public static
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。