tencent cloud

ReceiveMessage
Last updated: 2025-11-25 10:54:31
ReceiveMessage
Last updated: 2025-11-25 10:54:31

1. API Description

Domain name for API request: tdmq.intl.tencentcloudapi.com.

This API is used to receive messages sent to a specified Partitioned Topic. It supports only Partitioned Topic type. When there are no messages in the Partitioned Topic but the API is still called, it throws a ReceiveTimeout exception.

This API is used to batch receive policies.

This API is used to provide the following three parameters:.

MaxNumMessages: The maximum number of messages returned by the Receive API each time when using BatchReceive.
MaxNumBytes: the maximum size of messages returned by the Receive API in a single BatchReceive operation, in bytes.
Timeout: The maximum timeout period for each Receive API call when using BatchReceive is how long, in MS.

This API is used to disable the BatchReceive feature if none of the three parameters are specified. If any one of the three parameters has a value greater than 0, BatchReceive is enabled. BatchReceive completes when reaching the threshold specified in any one of the three parameters.

Note: MaxNumMessages and MaxNumBytes are subject to the size of ReceiveQueueSize for each receipt of messages. If ReceiveQueueSize is set to 5 and MaxNumMessages is set to 10, then BatchReceive will receive at most 5 messages at once rather than 10.

This API is used to return multiple messages at one time.

This API is used to Split multiple messages with the special character '###', allowing the business side to use Split tools in different languages to separate messages after receiving them.
Multiple MessageIDs use the special character '###' to separate with each other. After receiving the message, the business side can leverage the Split tool provided by different languages to separate different messages. (Used for filling in the necessary MessageID field information when calling the AcknowledgeMessage API.).

A maximum of 1000 requests can be initiated per second for this API.

We recommend you to use API Explorer
Try it
API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

2. Input Parameters

The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

Parameter Name Required Type Description
Action Yes String Common Params. The value used for this API: ReceiveMessage.
Version Yes String Common Params. The value used for this API: 2020-02-17.
Region Yes String Common Params. For more information, please see the list of regions supported by the product. This API only supports: ap-bangkok, ap-beijing, ap-chengdu, ap-chongqing, ap-guangzhou, ap-hongkong, ap-jakarta, ap-nanjing, ap-seoul, ap-shanghai, ap-shanghai-fsi, ap-shenzhen-fsi, ap-singapore, ap-tokyo, eu-frankfurt, na-ashburn, na-siliconvalley.
Topic Yes String Name of the topic which receives the message. It is better to be the full path of the topic, such as tenant/namespace/topic. If it is not specified, public/default will be used by default.
SubscriptionName Yes String Subscriber name
ReceiverQueueSize No Integer Default value: 1000. Messages received by the consumer will first be stored in the receiverQueueSize queue to tune the message receiving rate.
SubInitialPosition No String A parameter used to determine the position where the consumer initially receives messages. Valid values: Earliest (default), Latest.
MaxNumMessages No Integer This parameter is used to specify the maximum number of received messages in a batch for BatchReceivePolicy. The default value is 0, indicating that BatchReceivePolicy is disabled.
MaxNumBytes No Integer This parameter is used to specify the maximum body size (in bytes) of received messages in a batch for BatchReceivePolicy. The default value is 0, indicating that BatchReceivePolicy is disabled.
Timeout No Integer This parameter is used to specify the maximum wait timeout (in milliseconds) for receiving a batch of messages for BatchReceivePolicy. The default value is 0, indicating that BatchReceivePolicy is disabled.

3. Output Parameters

Parameter Name Type Description
MessageID String Unique primary key used to identify the message
MessagePayload String Content of the received message
AckTopic String Provided to the Ack API and used to acknowledge messages in the topic
ErrorMsg String Returned error message. If it is null, it means there is no error.
SubName String Returned subscriber names, used for creating Ack consumers
MessageIDList String BatchReceivePolicy specifies the messageids of multiple messages returned at one time, using '###' to distinguish different messageids.
MessagesPayload String BatchReceivePolicy specifies the message content of multiple messages returned at one time, using '###' to distinguish different message content.
RequestId String The unique request ID, generated by the server, will be returned for every request (if the request fails to reach the server for other reasons, the request will not obtain a RequestId). RequestId is required for locating a problem.

4. Example

Example1 Receiving Messages

Input Example

POST / HTTP/1.1
Host: tdmq.intl.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: ReceiveMessage
<Common request parameters>

{
    "Topic": "tenant/namespace/topic",
    "SubscriptionName": "\"test-sub\""
}

Output Example

{
    "Response": {
        "MessageID": "931087:81:0",
        "MessagePayload": "msg send",
        "AckTopic": "tenant/namespace/topic",
        "ErrorMsg": "success",
        "SubName": "test-sub",
        "MessageIDList": "931087:81:0",
        "MessagesPayload": "msg send",
        "RequestId": "bee03397-31dd-4688-8fe0-81c691c3c1ae"
    }
}

5. Developer Resources

SDK

TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

Command Line Interface

6. Error Code

The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

Error Code Description
FailedOperation.CreateProducerError An error occurred while creating the producer.
FailedOperation.CreatePulsarClientError An error occurred while creating the TDMQ client.
FailedOperation.MaxMessageSizeError The message size exceeds the upper limit of 1 MB.
FailedOperation.MessageIDError The uploaded msgID is incorrect.
FailedOperation.ReceiveError An error occurred while receiving the message.
FailedOperation.ReceiveTimeout Message receiving timed out. Please try again.
FailedOperation.SendMessageTimeoutError Message sending timed out.
FailedOperation.TopicTypeError Please use a partition topic.
InvalidParameter.TenantNotFound The uploaded tenant name is incorrect.
InvalidParameter.TokenNotFound The correct token was not obtained.
InvalidParameterValue.TopicNotFound The uploaded topic name is incorrect.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback