apache / rocketmq-spring

Apache RocketMQ Spring Integration
https://rocketmq.apache.org/
Apache License 2.0
2.12k stars 898 forks source link

Add syncSendDeliverTimeMills and syncSendDelayTimeMills API for RocketMQ 5.0 timer message #520

Closed RongtongJin closed 1 year ago

RongtongJin commented 1 year ago

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

baobeisuper commented 1 year ago

Hi, it doesn't work on RocketMQ 5.1. It took a while. Not effective

anigkus commented 7 months ago

That's it, FAIL...

Rocketmq Server Version

producer&consumer

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

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