tencent cloud

TDMQ for RocketMQ

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Introduction and Selection of the TDMQ Product Series
What Is TDMQ for RocketMQ
Strengths
Scenarios
Product Series
Comparison with Open-Source RocketMQ
High Availability
Quotas and Limits
Supported Regions
Basic Concepts
Billing
Billing Overview
Pricing
Billing Examples
Pay-as-you-go Switch to Monthly Subscription (5.x)
Renewal
Viewing Consumption Details
Refund
Overdue Payments
Getting Started
Getting Started Guide
Preparations
Step 1: Creating TDMQ for RocketMQ Resources
Step 2: Using the SDK to Send and Receive Messages (Recommended)
Step 2: Running the TDMQ for RocketMQ Client (Optional)
Step 3: Querying Messages
Step 4: Deleting Resources
User Guide
Usage Process Guide
Configuring Account Permissions
Creating the Cluster
Configuring the Namespace
Configuring the Topic
Configuring the Group
Connecting to the Cluster
Managing Messages
Managing the Cluster
Viewing Monitoring Data and Configuring Alarms
Cross-Cluster Message Replication
Use Cases
Naming Conventions for Common Concepts of TDMQ for RocketMQ
RocketMQ Client Use Cases
RocketMQ Performance Load Testing and Capacity Assessment
Access over HTTP
Client Risk Descriptions and Update Guide
Migration Guide for TencentCloud API Operations Related to RocketMQ 4.x Cluster Roles
Migration Guide
Disruptive Migration
Seamless Migration
Developer Guide
Message Types
Message Filtering
Message Retries
POP Consumption Mode (5.x)
Clustering Consumption and Broadcasting Consumption
Subscription Relationship Consistency
Traffic Throttling
​​API Reference(5.x)
History
API Category
Making API Requests
Topic APIs
Consumer Group APIs
Message APIs
Role Authentication APIs
Hitless Migration APIs
Cloud Migration APIs
Cluster APIs
Data Types
Error Codes
​​API Reference(4.x)
SDK Reference
SDK Overview
5.x SDK
4.x SDK
Security and Compliance
Permission Management
CloudAudit
Deletion Protection
FAQs
4.x Instance FAQs
Agreements
TDMQ for RocketMQ Service Level Agreement
Contact Us

Scheduled and Delayed Messages

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-01-23 17:52:23
This document mainly introduces the concept and use of scheduled and delayed messages in TDMQ for RocketMQ.

Relevant Concepts

Scheduled messages: After a message is sent to the server, the business may want the consumer to receive it at a later time point rather than immediately. Messages of this type are called scheduled messages.
Delayed messages: After a message is sent to the server, the business may want the consumer to receive it after a period of time rather than immediately. Messages of this type are called delayed messages.
In fact, delayed messages can be seen as a special usage of scheduled messages, and their ultimate implementation effects are the same.

Usage Methods

Open-source Apache RocketMQ does not provide an API for users to freely set delay times. To ensure compatibility with the open-source RocketMQ client, TDMQ for RocketMQ implements scheduled sending by adding specific property key-value pairs to messages. You can schedule a message for delivery at any time within a certain range (40 days) by adding the __STARTDELIVERTIME value to the property of the message. For delayed messages, you can first calculate the scheduled delivery timestamp and then send them as scheduled messages.
The following code example shows how to use the scheduled and delayed messages of TDMQ for RocketMQ. View the complete sample code.
For delayed messages, first calculate the scheduled delivery timestamp using System.currentTimeMillis() + delayTime and then send them as scheduled messages.
4.x Client
5.X Client

Message msg = new Message("test-topic", ("message content").getBytes(StandardCharsets.UTF_8));

// Set the message to be sent 10 seconds later.
long delayTime = System.currentTimeMillis() + 10000;
// Set __STARTDELIVERTIME into the property of msg.
msg.putUserProperty("__STARTDELIVERTIME", String.valueOf(delayTime));

SendResult result = producer.send(msg);
System.out.println("Send delay message: " + result);

Duration messageDelayTime = Duration.ofSeconds(10); final Message message = provider.newMessageBuilder() // Set topic for the current message. .setTopic(topic) // Message secondary classifier of message besides topic. .setTag(tag) // Key(s) of the message, another way to mark message besides message id. .setKeys("yourMessageKey-3ee439f945d7") // Set expected delivery timestamp of message. .setDeliveryTimestamp(System.currentTimeMillis() + messageDelayTime.toMillis()) .setBody(body) .build();

Use Limits

When you use delayed messages, make sure that the clocks on the clients and servers are the same (all regions use UTC+8) to avoid time differences.
Scheduled and delayed messages have a time deviation of approximately 1 second.
The allowable time range for scheduled and delayed messages varies depending on the cluster specifications. For more information, see Product Series.
For scheduled messages, the scheduled time should be a future time. If it is earlier than the current time, the messages are delivered to consumers immediately.

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백