You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/07/31 22:13:26 UTC

[GitHub] [rocketmq-site] RockChuLee commented on a diff in pull request #166: Delay message sending

RockChuLee commented on code in PR #166:
URL: https://github.com/apache/rocketmq-site/pull/166#discussion_r934046346


##########
docs/09-英文/02-Producer/07message3.md:
##########
@@ -0,0 +1,45 @@
+# Delay Message Sending
+
+The delay message sending means that when a message is sent to Apache RocketMQ, instead of delivering the message immediately, it is delivered to the Consumer for consumption after delaying a certain period of time.
+
+Apache RocketMQ supports a total of 18 levels of delayed delivery, the detail is as follows:
+
+| delay level | delay time | delay level | delay time |
+|-------------------|------|-------------------|-------|
+| 1                 | 1s   | 10                | 6min  |
+| 2                 | 5s   | 11                | 7min  |
+| 3                 | 10s  | 12                | 8min  |
+| 4                 | 30s  | 13                | 9min  |
+| 5                 | 1min | 14                | 10min |
+| 6                 | 2min | 15                | 20min |
+| 7                 | 3min | 16                | 30min |
+| 8                 | 4min | 17                | 1h    |
+| 9                 | 5min | 18                | 2h    |
+
+The sample code for the delay message sending is as follows:
+
+```javascript {10,11}
+public class ScheduledMessageProducer {
+    public static void main(String[] args) throws Exception {
+        // Instantiate a producer to send scheduled messages
+        DefaultMQProducer producer = new DefaultMQProducer("ExampleProducerGroup");
+        // Launch producer
+        producer.start();
+        int totalMessagesToSend = 100;
+        for (int i = 0; i < totalMessagesToSend; i++) {
+            Message message = new Message("TestTopic", ("Hello scheduled message " + i).getBytes());
+            // This message will be delivered to consumer 10 seconds later.
+            message.setDelayTimeLevel(3);
+            // Send the message
+            producer.send(message);
+        }
+        
+        // Shutdown producer after use.
+        producer.shutdown();
+    }
+    
+}
+```
+:::tip
+The most important thing is to set the delay level for the message. In the above sample code, the delay level is set to 3, which means that after the sender sends the message, it takes 10s for the consumer to receive it

Review Comment:
   Hi, @tsunghanjacktsai ,
   
   Nice to talk with you, your suggestion is good. I solve all them and learn a lot. Thanks



-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org