JAVA全系列 教程
3762个小节阅读:7095k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<version>2.2.3</version>
</dependency>
xxxxxxxxxx
rocketmq:
# nameserver地址
name-server: 192.168.47.100:9876
producer:
# 生产组
group: my-group1
# 发送消息超时时间
send-message-timeout: 300000
生产者rocketMQTemplate会根据配置的Namesrv地址自动生成一个bean注入spring容器中,我们在使用的时候直接添加@Resource 或者@Autowired 注解即可。当前的版本支持直接发送一个对象或字符串,RocketMQ 使用 JSON 作为序列化方式进行传输。
xxxxxxxxxx
package com.itbaizhan.produce;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
public class MessageProduce {
@Autowired
private RocketMQTemplate rocketMQTemplate; // 直接注入生产者
@Value("${demo.rocketmq.topic}")
private String topic;
/**
* 发送消息
* @param topic 主题
* @param message 消息
* @return
*/
public SendResult sendMessage( String message){
return rocketMQTemplate.syncSend(topic, message);
}
}
报错信息
xxxxxxxxxx
*************************** APPLICATION FAILED TO START ***************************
Description:
Field rocketMQTemplate in com.dayuwebtech.dayupay.common.rocketmq.impl.SendPayReNotifyMessageImpl required a bean of type 'org.apache.rocketmq.spring.core.RocketMQTemplate' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action: Consider defining a bean of type 'org.apache.rocketmq.spring.core.RocketMQTemplate' in your configuration.
我们要在resources文件夹中,新建META-INF/spring文件夹,在里面新建一个叫org.springframework.boot.autoconfigure.AutoConfiguration.imports的文件里面填入 org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration