1557947 Jps
230238 NamesrvStartup
启动broker
[root@ecs-kunpeng-0006 rocketmq]# bin/mqbroker -n localhost:9876
- 问题1:启动
Broker
时报错:
Error: VM option ‘UseG1GC’ is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
- 解决方法:查看bin/mqbroker的脚本可发现,其中调用了runbroker.sh,编辑runbroker.sh,发现其中有UseG1GC的可选项(实验性的选项),删除这一行即可。
删除包含UseG1GC的一行配置
[root@ecs-kunpeng-0006 rocketmq]# vi bin/runbroker.sh
JAVA_OPT=“${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0”
- 问题2:
There is insufficient memory for the Java Runtime Environment to continue.
Native memory allocation (mmap) failed to map 8589934592 bytes for committing reserved memory.
An error report file with more information is saved as:
/usr/local/rocketmq/bin/hs_err_pid10503.log
编辑runbroker.sh
[root@ecs-kunpeng-0006 rocketmq]# vi bin/runbroker.sh
JAVA_OPT=“${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g”
修改为:
JAVA_OPT=“${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m”
尝试重新启动
[root@ecs-kunpeng-0006 rocketmq]# bin/mqbroker -n localhost:9876
The broker[ecs-kunpeng-0006, 172.17.0.1:10911] boot success. serializeType=JSON and name server is localhost:9876
查看进程
[root@ecs-kunpeng-0006 rocketmq]# jps
1657041 BrokerStartup
1659988 Jps
230238 NamesrvStartup
- 问题3:前面步骤启动之后,无法通过公网访问
如果 rocketmq
部署在公网上,要通过外网访问时,需进行如下配置。
1. 在conf/broker.conf中添加:
[root@ecs-kunpeng-0006 rocketmq]# vi conf/broker.conf
brokerIP1=你的公网IP
2. 通过这条命令启动broker:
[root@ecs-kunpeng-0006 rocketmq]# bin/mqbroker -n 你的公网IP:9876 -c conf/broker.conf
The broker[broker-a, 你的公网IP:10911] boot success. serializeType=JSON and name server is 你的公网IP:9876
否则远程客户端报错:
org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout
基于SpringBoot的远程客户端
- pom.xml中添加依赖
org.apache.rocketmq
rocketmq-client
4.7.1
- 编写测试类
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootRocketProducerApplicationTests {
@Test
public void producer() throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
DefaultMQProducer producer = new DefaultMQProducer(“my-producer”);
producer.setNamesrvAddr(“你的公网IP:9876”);
producer.start();
Message message = new Message(“myTopic01”, “Hello RocketMQ!”.getBytes());
SendResult sendResult = producer.send(message);
System.out.println("Message send Success, result: " + sendResult);
producer.shutdown();
System.out.println(“Producer shutdown!”);
}
- 运行测试方法
-
报错:No route info of this topic: myTopic01
-
解决:配置启动
broker
时自动创建broker
,附带参数:autoCreateTopicEnable=true
附带参数:autoCreateTopicEnable=true
[root@ecs-kunpeng-0006 rocketmq]# bin/mqbroker -n 你的公网IP:9876 -c conf/broker.conf autoCreateTopicEnable=true
- 验证主题是否创建成功,验证测试消息是否发送成功
这里可使用 RocketMQ
官方提供的 Web
管理控制台。下载地址:https://github.com/apache/rocketmq-externals/tree/master/rocketmq-console,本身也是个基于 SpringBoot
的 Web
项目,启动前先修改为自己的 RocketMQ
地址,默认运行在 8080
端口。
后台启动broker
后台启动
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
面试准备+复习分享:
为了应付面试也刷了很多的面试题与资料,现在就分享给有需要的读者朋友,资料我只截取出来一部分哦
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门即可获取!
14a7895254671a72faed303032d36.jpg" alt=“img” style=“zoom: 33%;” />
面试准备+复习分享:
为了应付面试也刷了很多的面试题与资料,现在就分享给有需要的读者朋友,资料我只截取出来一部分哦
[外链图片转存中…(img-dk2gdtr3-1712417537101)]
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门即可获取!