<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
rocketmq:
name-server: 127.0.0.1:9876
producer:
group: test
consumer:
group: test
pullBatchSize: 10
注:rocketmq不再spring下,应放到做外层
@Component
public class RocketMQProducer {
@Autowired
private RocketMQTemplate rocketMQTemplate;
public void sendMsg(String topic, String msg)
{
System.out.println("发送报文:" + msg);
this.rocketMQTemplate.convertAndSend(topic, msg);
}
}
@Component
@RocketMQMessageListener(topic = "test", consumerGroup = "${rocketmq.consumer.group}")
public class RocketMQConsumer implements RocketMQListener<String> {
@Override
public void onMessage(String s) {
System.out.println("接收到rocketmq消息:" + s);
}
}