整合springboot

添加依赖

<!-- https://mvnrepository.com/artifact/org.apache.rocketmq/rocketmq-spring-boot-starter -->
<dependency>
    <groupId>org.apache.rocketmq</groupId>
    <artifactId>rocketmq-spring-boot-starter</artifactId>
    <version>2.0.4</version>
</dependency>

配置文件

rocketmq.name-server=ip1:port1;ip2:port2
rocketmq-producer.group=groupName

生产者

 @Autowired
 private RocketMQTemplate rocketMQTemplate;
 
 public void produce(){
       rocketMQTemplate.converAndSent("topicName","消息主体");
    
  }
  

消费者

@RocketMQMessageListener(topic = "topicName",consumerGroup = "groupName")
public class Consumer imlements RocketMQListener<String>{
@Override
public void onMessage(String message){
    System.out.println("消费"+message);
}

}