All Products
Search
Document Center

ApsaraMQ for RocketMQ:Scheduled messages and delayed messages

Last Updated:Mar 10, 2026

Scheduled messages and delayed messages both defer delivery to consumers. The difference is how you specify the timing:

  • Scheduled message: you specify an absolute timestamp. The broker holds the message and delivers it at that exact point in time.

  • Delayed message: you specify a relative duration. The broker holds the message and delivers it after that duration elapses from the time it was sent.

The underlying mechanism is the same. The broker stores the message and releases it to consumers when the target time arrives.

Use cases

  • Order timeout handling: When a user creates an order in an e-commerce checkout flow, send a delayed message with a 30-minute delay. After 30 minutes, the consumer checks whether payment is complete. If not, it cancels the order. If payment succeeded, it ignores the message.

  • Timed notifications: Send a scheduled message set to a specific time -- for example, 9:00 AM the next day -- to trigger a push notification or reminder.

Set the delivery time

Both message types use the same parameter: msg.setStartDeliverTime, which accepts a millisecond-precision Unix timestamp.

  • Scheduled message: pass the absolute timestamp of the target delivery time.

  • Delayed message: pass System.currentTimeMillis() + delayMillis, where delayMillis is the delay duration in milliseconds.

Code examples

Delay a message by 10 minutes from now:

// Calculate the delivery timestamp: current time + 10 minutes
long deliverTime = System.currentTimeMillis() + 10L * 60 * 1000;
msg.setStartDeliverTime(deliverTime);

Schedule a message for a specific date and time:

// Schedule delivery for 2024-06-15 14:30:00 (UTC+8)
// Millisecond Unix timestamp: 1718433000000
long deliverTime = 1718433000000L;
msg.setStartDeliverTime(deliverTime);

Rules and limits

RuleDetails
Minimum delivery timeMust be later than the current timestamp. If the specified time is in the past, the message is delivered immediately.
Maximum scheduling window40 days from the current time. Messages that exceed this window fail to send.
Time unitMilliseconds
Topic type requirementThe topic must be created with Message Type set to Scheduled/Delayed Message in the ApsaraMQ for RocketMQ console. A topic only accepts messages that match its configured type.
Message retentionUp to 3 days. For example, if a message is scheduled for delivery in 5 days and is not consumed, it is deleted on the 8th day (5-day delay + 3-day retention).

Delivery precision

Scheduled and delayed messages are not guaranteed to arrive at the exact specified time due to the following factors:

  • Baseline latency: expect 1 to 2 seconds of delivery latency.

  • Message backlog: if accumulated messages exist in the queue, scheduled and delayed messages are queued behind them and may arrive later than the target time.

  • Clock skew: the StartDeliverTime value is evaluated against the broker clock. If the client clock differs from the broker clock, the actual delivery time may not match the timestamp set by the producer.

Sample code

For complete producer and consumer examples, see the following guides organized by protocol and language.

TCP

LanguageLink
JavaSend and receive scheduled messages
JavaSend and subscribe to delayed messages
C++Send and subscribe to scheduled messages
.NETSend and receive scheduled messages

HTTP

LanguageLink
JavaSend and subscribe to scheduled messages and delayed messages
GoSend and subscribe to scheduled messages and delayed messages
PythonSend and subscribe to scheduled messages and delayed messages
Node.jsSend and subscribe to scheduled messages and delayed messages
PHPSend and subscribe to scheduled messages and delayed messages
C#Send and subscribe to scheduled messages and delayed messages
C++Send and subscribe to scheduled messages and delayed messages