# pom.xml
```xml
<!-- 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.3.0</version>
<exclusions>
<!--although have vulnerability, but must not exclusion this `commons-collections`, otherwise confused. -->
<!-- <exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>-->
<!-- <exclusion>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</exclusion>-->
</exclusions>
</dependency>
Other
After 2.3.0 the @Import(RocketMQAutoConfiguration.class) annotation must be added to the start application class, otherwise RocketMQTemplate will not be injected.
In 2.2.2 and 2.2.1 version, If at startup show log warning, need add System.setProperty("rocketmq.client.logUseSlf4j", "true"), but if contains 2.2.0 and below and contains 2.3.0 and above, then no need.
rocketmq: name-server: 127.0.0.1:9876 producer: group: PRODUCER_GROUP_MANAGER # Default: none send-message-timeout: 10000 # Default: 3000s
import lombok.extern.slf4j.Slf4j; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.spring.annotation.MessageModel; import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; import org.apache.rocketmq.spring.core.RocketMQListener; import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener; import org.springframework.stereotype.Component;
@Component @Slf4j @RocketMQMessageListener(topic = "TOPIC_TEST", consumerGroup = "SPRING_TOPIC_CONSUMER", messageModel = MessageModel.CLUSTERING) public class StringConsumer1 implements RocketMQListener, RocketMQPushConsumerLifecycleListener {
}
import lombok.extern.slf4j.Slf4j; import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.springframework.messaging.support.GenericMessage; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController @Slf4j public class TestController { @Resource //@Autowired private RocketMQTemplate rocketMQTemplate;
}
2.3.0
the@Import(RocketMQAutoConfiguration.class)
annotation must be added to the start application class, otherwiseRocketMQTemplate
will not be injected.2.2.2
and2.2.1
version, If at startup show log warning, need addSystem.setProperty("rocketmq.client.logUseSlf4j", "true")
, but if contains2.2.0
and below and contains2.3.0
and above, then no need.