You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "anigkus (via GitHub)" <gi...@apache.org> on 2024/04/17 03:21:49 UTC
Re: [I] Add syncSendDeliverTimeMills and syncSendDelayTimeMills API for RocketMQ 5.0 timer message [rocketmq-spring]
anigkus commented on issue #520:
URL: https://github.com/apache/rocketmq-spring/issues/520#issuecomment-2060273902
# That's it, FAIL...
## Rocketmq Server Version
* rocketmq-all-5.1.4-bin-release
## pom.xml
```xml
<?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>io.github.anigkus</groupId>
<artifactId>rocketmq-spring-boot-starter-230-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rocketmq-spring-boot-starter-230-demo</name>
<description>Demo project for Spring Boot</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>
```
## producer&consumer
```java
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);
}
}
```
## Log
```log
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
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org