赞
踩
<!-- SpringBoot 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- RocketMQ 依赖 --> <dependency> <groupId>org.apache.rocketmq</groupId> <artifactId>rocketmq-spring-boot-starter</artifactId> <version>2.2.3</version> </dependency>
rocketmq.name-server=127.0.0.1:9876
rocketmq.producer.group=BREAD_ORDER_GROUP
docker search apache/rocketmq
docker pull apache/rocketmq:5.1.0
docker images
1.4.1 创建Broker挂载文件夹
mkdir /home/rocketmq/broker/bin -p
mkdir /home/rocketmq/broker/conf -p
mkdir /home/rocketmq/broker/logs -p
mkdir /home/rocketmq/broker/store -p
1.4.2 创建NameServer挂载文件夹
mkdir /home/rocketmq/nameserver/bin -p
mkdir /home/rocketmq/nameserver/conf -p
1.5.1 启动NamerServer容器
docker run -d \
--privileged=true \
--name testnameserver \
apache/rocketmq:5.1.0 sh mqnamesrv
1.5.2 复制NameServer启动脚本
docker cp testnameserver:/home/rocketmq/rocketmq-5.1.0/bin/runserver.sh /home/rocketmq/nameserver/bin/runserver.sh
1.5.3 修改脚本文件
vim /home/rocketmq/nameserver/bin/runserver.sh
# 注释该行
calculate_heap_sizes
1.5.4 停止并删除NameServer容器
docker stop testnameserver
docker rm testnameserver
1.5.5 启动Broker容器
docker run -d \
--name testbroker \
--privileged=true \
apache/rocketmq:5.1.0 \
sh mqbroker
1.5.6 复制Broker启动脚本
docker cp testbroker:/home/rocketmq/rocketmq-5.1.0/bin/runbroker.sh /home/rocketmq/broker/bin/runbroker.sh
1.5.7 修改脚本文件
vim /home/rocketmq/broker/bin/runbroker.sh
# 注释该行
calculate_heap_sizes
1.5.8 停止并删除Broker容器
docker stop testbroker
docker rm testbroker
vim /home/rocketmq/broker/conf/broker.conf
# 你的NameServer服务器公网IP地址与端口号 namesrvAddr=127.0.0.1:9876 # 集群名称 brokerClusterName = DefaultCluster # 节点名称 brokerName = broker-a # broker id节点ID, 0 表示 master, 其他的正整数表示 slave,不能小于0 brokerId = 0 # Broker服务地址(你的服务器公网IP地址) brokerIP1 = 127.0.0.1 # Broker角色 brokerRole = ASYNC_MASTER # 刷盘方式 flushDiskType = ASYNC_FLUSH # 删除时间(4点) deleteWhen = 04 # 文件保留时间(72小时) fileReservedTime = 72 # 是否允许Broker自动创建Topic,建议线下开启,线上关闭 autoCreateTopicEnable = true # 是否允许Broker自动创建订阅组,建议线下开启,线上关闭 autoCreateSubscriptionGroup = true # 检测可用的磁盘空间大小,超过后会写入报错(95%) diskMaxUsedSpaceRatio=95
chmod -R 777 /home/rocketmq/
1.8.1 启动NameServer容器
docker run -d \
--privileged=true \
--restart=always \
--name nameserver \
-p 9876:9876 \
-v /home/rocketmq/nameserver/logs:/home/rocketmq/logs \
-v /home/rocketmq/nameserver/bin/runserver.sh:/home/rocketmq/rocketmq-5.1.0/bin/runserver.sh \
-e "MAX_HEAP_SIZE=256M" \
-e "HEAP_NEWSIZE=128M" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
apache/rocketmq:5.1.0 sh mqnamesrv
1.8.2 启动Broker容器
docker run -d \
--restart=always \
--name broker \
-p 10911:10911 -p 10909:10909 \
--privileged=true \
-v /home/rocketmq/broker/logs:/root/logs \
-v /home/rocketmq/broker/store:/root/store \
-v /home/rocketmq/broker/conf/broker.conf:/home/rocketmq/broker.conf \
-v /home/rocketmq/broker/bin/runbroker.sh:/home/rocketmq/rocketmq-5.1.0/bin/runbroker.sh \
-e "MAX_HEAP_SIZE=512M" \
-e "HEAP_NEWSIZE=256M" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
apache/rocketmq:5.1.0 \
sh mqbroker -c /home/rocketmq/broker.conf
docker ps
docker search apacherocketmq/rocketmq-dashboard
docker pull apacherocketmq/rocketmq-dashboard
# 你的NameServer服务器公网IP地址与端口号
docker run -d \
--restart=always \
--name dashboard \
-e "JAVA_OPTS=-Xmx256M -Xms256M -Xmn128M -Drocketmq.namesrv.addr=127.0.0.1:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" \
-p 8082:8080 \
apacherocketmq/rocketmq-dashboard
docker ps
# 你的服务器公网IP地址
http://127.0.0.1:8082/
# 文件名信息
org.springframework.boot.autoconfigure.AutoConfiguration.imports
# 文件内容
org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration
package com.catalpa.study.test; import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class OrderController { @Autowired private RocketMQTemplate rocketMQTemplate; @RequestMapping("/test") public String order() { String test = "123测试"; rocketMQTemplate.convertAndSend("ORDER_TOPIC", test); return test; } }
package com.catalpa.study.listener;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;
@Service
@RocketMQMessageListener(topic = "ORDER_TOPIC", consumerGroup = "BREAD_ORDER_GROUP", consumeMode = ConsumeMode.ORDERLY)
public class NormalRocketMqListener implements RocketMQListener<String> {
@Override
public void onMessage(String s) {
System.out.println("普通订阅-接收到的信息:{}"+ s);
}
}
http://127.0.0.1:8081/test
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。