rocketmq / rocketmq-spring-boot-starter

Help developers quickly integrate RocketMQ in Spring Boot. Support the Spring Message specification to facilitate developers to quickly switch from other MQ to RocketMQ.
https://www.rocketmq.org
Apache License 2.0
77 stars 22 forks source link

rocketmq-spring-boot-starter

License

Quick Start

<!--add dependency in pom.xml-->
<dependency>
    <groupId>org.rocketmq.spring.boot</groupId>
    <artifactId>rocketmq-spring-boot-starter</artifactId>
    <version>1.0.0.RELEASE</version>
</dependency>

Consume Message

## application.properties
spring.rocketmq.name-server=127.0.0.1:9876

More relevant configurations for produce:


spring.rocketmq.producer.retry-times-when-send-async-failed=0
spring.rocketmq.producer.send-msg-timeout=300000
spring.rocketmq.producer.compress-msg-body-over-howmuch=4096
spring.rocketmq.producer.max-message-size=4194304
spring.rocketmq.producer.retry-another-broker-when-not-store-ok=false
spring.rocketmq.producer.retry-times-when-send-failed=2

Note:

Maybe you need change 127.0.0.1:9876 with your real NameServer address for RocketMQ
@SpringBootApplication
@EnableRocketMQ
public class RocketMQApplication {
    public static void main(String[] args) {
        SpringApplication.run(RocketMQApplication .class,args);
    }
}

@Slf4j
@Service
@RocketMQListener(topic = "topic-1")
public class MyConsumer1 {
     @RocketMQMessage(messageClass = String.class,tag = "tag-1")
     public void onMessage(String message) {
         log.info("received message: {}", message);
     }
}