rocketmq可以发送延时消息,通过设置消息的延时等级即可。rocketmq的延时消息不支持任意时间的延迟,而是根据下面的固定的时间选择一个来延迟
"1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h"
消息生产者
通过设置setDelayTimeLevel来实现
例如3 即是10s
public class SyncProducer {
public static void main(String[] args) throws Exception{
//Instantiate with a producer group name
DefaultMQProducer producer = new DefaultMQProducer("producer_group_01");
//Specify name server addresses
producer.setNamesrvAddr("localhost:9876");
//Launch the instance
producer.start();
for(int i = 0; i < 10; i++){
//Create a message instance, specifying topic, tag and message body.
Message msg = new Message("TopicTest",
"TagA",
("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));