Closed RongtongJin closed 1 year ago
Hi, it doesn't work on RocketMQ 5.1. It took a while. Not effective
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>anigkus.github.io</groupId>
<artifactId>experiment-rocketmq-spring-boot-starter-230</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rocketmq-spring-boot-starter-230-demo</name>
<description>Experiment rocketmq-spring-boot-starter 2.3.0</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<!-- <artifactId>rocketmq-v5-client-spring-boot-starter</artifactId>-->
<version>2.3.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.2.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2023.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
import jakarta.annotation.Resource;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.messaging.support.GenericMessage;
import java.util.Date;
import java.util.HashMap;
@SpringBootApplication
public class ProducerApplication implements CommandLineRunner {
@Resource
private RocketMQTemplate rocketMQTemplate;
private String springTopic = "string-topic";
public static void main(String[] args) {
SpringApplication.run(ProducerApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
rocketMQTemplate.syncSendDelayTimeMills(springTopic, "Hello, World, syncSendDelayTimeMills:" + (new Date()), 10 * 1000L);
rocketMQTemplate.syncSendDeliverTimeMills(springTopic, "Hello, World, syncSendDeliverTimeMills:" + (new Date()), (System.currentTimeMillis() + 10 * 1000));
}
}
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;
import java.util.Date;
@Service
@RocketMQMessageListener(topic = "string-topic", consumerGroup = "string_consumer")
public class StringConsumer implements RocketMQListener<String> {
@Override
public void onMessage(String message) {
System.out.printf((new Date()) + "------- StringConsumer received: %s \n", message);
}
}
Wed Apr 17 10:58:04 CST 2024------- StringConsumer received: Hello, World, syncSendDeliverTimeMills:Wed Apr 17 10:58:03 CST 2024
Wed Apr 17 10:58:04 CST 2024------- StringConsumer received: Hello, World, syncSend:Wed Apr 17 10:58:03 CST 2024
The issue tracker is ONLY used for bug report and feature request.
Any question or RocketMQ proposal please use our mailing lists.
Add syncSendDeliverTimeMills and syncSendDelayTimeMills API for RocketMQ 5.0 timer message