写在前面:
继续记录自己的SpringBoot学习之旅,这次是SpringBoot应用相关知识学习记录。若看不懂则建议先看前几篇博客,详细代码可在我的Gitee仓库SpringBoot克隆下载学习使用!
3.5.4.5 SpringBoot整合RocketMQ
3.5.4.5.1 RocketMQ安装
- 点击RockedMQ网站下载解压,这里选择4.9.2 Binary版本
- 配置环境变量,默认端口号是9876,如图
![![[Pasted image 20221117144535.png]]](https://img-blog.csdnimg.cn/d176057fc49941b584d1a3132dee6666.png)
![![[Pasted image 20221117144433.png]]![[Pasted image 20221117144345.png]]](https://img-blog.csdnimg.cn/5e37bea707ce4c198eb62666dc6d97df.png)

- 启动namespaceServer服务,点击bin里中的mqnamesrv,如图
![![[Pasted image 20221117144937.png]]](https://img-blog.csdnimg.cn/bbf4d6df090746d79440c5391e590879.png)
![![[Pasted image 20221117144951.png]]](https://img-blog.csdnimg.cn/ede53195a90f41d6afd677f28c2cfdb4.png)
- 启动mqbroker服务,同上,点击mqbroker.cmd,如图
![![[Pasted image 20221117154514.png]]](https://img-blog.csdnimg.cn/d4a166cf211c4f1a8c800d5f36d7fc2c.png)
**注:**若报错则是jdk目录安装在C盘里的Program Files中,解决办法是打开打开runbroker.cmd,然后将‘%CLASSPATH%’加上英文双引号,如图![![[Pasted image 20221117154616.png]]](https://img-blog.csdnimg.cn/e17a936e3e064ba2a04a82804bc6f34d.png)
- 消息生产消费测试
- 生产者测试,cmd命令输入
tools tools org.apache.rockedmq.example.quickstart.Producer,如图即可![![[Pasted image 20221117155437.png]]](https://img-blog.csdnimg.cn/6b862273c3b74b8bb2d9bac1b74385e8.png)
- 消费者测试,cmd命令输入
tools org.apache.rocketmq.example.quickstart.Consumer,如图![![[Pasted image 20221117155522.png]]](https://img-blog.csdnimg.cn/66cbad6e637c4d60b83d9b7b0073c19b.png)
- 生产者测试,cmd命令输入
3.5.4.5.2 整合
- SpringBoot添加坐标,在maven仓库搜索RocketMQ找到有Starter的,复制粘贴,如图
![![[Pasted image 20221117155924.png]]](https://img-blog.csdnimg.cn/251182aebca64fde8459c94cbee46d32.png)
- 配置yml,如图
![![[Pasted image 20221117161540.png]]](https://img-blog.csdnimg.cn/e31ad03e4af5479f8d7a2d3a7560469e.png)
- 编辑实现类发送同步消息,并将之前实现类@Service注释掉,如下:
@Service
public class MessageServiceRocketmqImpl implements MessageService {
@Autowired
private RocketMQTemplate rocketMQTemplate;
@Override
public void sendMessage(String id) {
System.out.println("待发送短信的订单已纳入处理队列(rocketmq),id: " + id);
rocketMQTemplate.convertAndSend("order_id",id);
}
@Override
public String doMessage() {
return null;
}
}
,运行后如图

- 编写监听器,如下:
@Component
@RocketMQMessageListener(topic = "order_id",consumerGroup = "group_rocketmq_01")
public class MessageListener implements RocketMQListener<String> {
@Override
public void onMessage(String id) {
System.out.println("已完成短信发送业务(rocketmq),id=" + id);
}
}
,运行后如图![![[Pasted image 20221117163447.png]]](https://img-blog.csdnimg.cn/eeb64f7889874842afed1855923f0076.png)
- 编辑实现类发送异步消息,同上,更改如图
![![[Pasted image 20221117164111.png]]](https://img-blog.csdnimg.cn/194174cf22be479c8de885773134380e.png)
,运行如图![![[Pasted image 20221117164133.png]]](https://img-blog.csdnimg.cn/7dac2b1a9a10486884002f06aab87d46.png)
3.5.4.6 SpringBoot整合kafka
3.5.4.6.1 Kafka安装
- 点击Kafka网站下载版本,选择2.8.2版本
- 下载后解压缩即可
- 启动zookeeper服务,默认端口2181,CMD命令如下
zookeeper-server-start.bat ../../config/zookeeper.properties,若报错命令行太长,使用短的文件名 - 启动kafka服务,默认端口9092,命令
kafka-server-start.bat ../../config/server.properties即可
3.5.4.6.2 kafka测试
- 创建topic,cmd命令
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic demo,如图![![[Pasted image 20221118190835.png]]](https://img-blog.csdnimg.cn/c9c0909496564ae5b77cff7029a8c7d9.png)
- 查看topic,cmd命令
kafka-topics.bat --zookeeper 127.0.0.1:2181 --list,如图![![[Pasted image 20221118191050.png]]](https://img-blog.csdnimg.cn/950c9a487e0d4b2b8f7db0291fab0aa8.png)
- 启动生产者,cmd命令
kafka-console-producer.bat --broker-list localhost:9092 --topic demo - 启动消费者,cmd命令
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic demo --from-beginning - 生产者与消费者交互,生产者操作如图
![![[Pasted image 20221118193944.png]]](https://img-blog.csdnimg.cn/cdb1b9e0536e4baaa4506cceacf095b3.png)
,消费者如图
![![[Pasted image 20221118193959.png]]](https://img-blog.csdnimg.cn/fdffa2c1f46d4c2382ca0498fee9eea9.png)
3.5.4.6.3 整合
- 添加坐标,如下:
<!-- kafka-->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
- 配置yml,如图
![![[Pasted image 20221118200846.png]]](https://img-blog.csdnimg.cn/aa812be8485042daa796eccc7d47f252.png)
- 添加实现类与监听器,如图
![![[Pasted image 20221118200900.png]]](https://img-blog.csdnimg.cn/c906db6c115c4591a04074e854dd53bd.png)
添加监听器如图![![[Pasted image 20221118200919.png]]](https://img-blog.csdnimg.cn/1214c81435ce4d59811aee528ab154e8.png)
,结果如图![![[Pasted image 20221118201041.png]]](https://img-blog.csdnimg.cn/fd7ad4eef7584437b41eb78b0c3cd286.png)
![![[Pasted image 20221118201058.png]]](https://img-blog.csdnimg.cn/9314a1545ffe4335b8e82fdb86b62d38.png)
















![在裸机上输出Hello,world! [rCore-lab1]](https://img-blog.csdnimg.cn/75f6643faa3b41ab807b57ad4c700f4b.png#pic_center)


![[机器翻译]——pivot-based zero-shot translation based on fairseq](https://img-blog.csdnimg.cn/65c2410e90f74c1dbb52b7fa15be808c.png)