Domain name for API request: tdmq.tencentcloudapi.com.
Currently, the ReceiveMessage
API only supports partitioned topics. It is used to receive messages sent to a specified partitioned topic. If it is called when there are no messages in the partitioned topic, the ReceiveTimeout
exception will be reported.
Instructions on how to use BatchReceivePolicy
:
BatchReceive
has three parameters:
● MaxNumMessages
: The maximum number of messages returned by Receive
when BatchReceive
is used.
● MaxNumBytes
: The maximum size (in bytes) of the message returned by Receive
when BatchReceive
is used.
● Timeout
: The maximum timeout period (in milliseconds) of calling Receive
when BatchReceive
is used.
By default, if you don’t specify any of the three parameters, the BatchReceive
feature is disabled; if one of the three parameter values is above zero, BatchReceive
is enabled. BatchReceive
will be disabled when any of the three parameter values reaches the threshold you specify.
Note: The values of both MaxNumMessages
and MaxNumBytes
are subject to the value of ReceiveQueueSize
. If the values of ReceiveQueueSize
and MaxNumMessages
are 5 and 10, respectively, you can receive up to five rather than 10 messages when BatchReceive
is used.
The API configured with BatchReceivePolicy
returns multiple messages at a time.
MessageID
field information required for calling the AcknowledgeMessage
API.A maximum of 1000 requests can be initiated per second for this API.
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 | No | String | Common Params. This parameter is not required for this API. |
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. |
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 an empty string, no error occurred. Note: this field may return null, indicating that no valid values can be obtained. |
SubName | String | Returned subscriber name, which will be used when an acknowledgment consumer is created. Note: this field may return null, indicating that no valid values can be obtained. |
MessageIDList | String | MessageIDs returned by BatchReceivePolicy at a time, which are separated by “###”.Note: This field may return null, indicating that no valid values can be obtained. |
MessagesPayload | String | Message contents returned by BatchReceivePolicy at a time, which are separated by “###”.Note: This field may return null, indicating that no valid values can be obtained. |
RequestId | String | The unique request ID, which is returned for each request. RequestId is required for locating a problem. |
POST / HTTP/1.1
Host: tdmq.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: ReceiveMessage
<Common request parameters>
{
"Topic": "tenant/namespace/topic",
"SubscriptionName": "\"test-sub\""
}
{
"Response": {
"RequestId": "36713f94-d07d-4b96-babf-42d139276f23",
"MessageID": "71:12:0:0",
"MessageIDList": "",
"MessagesPayload": "",
"MessagePayload": "hello TDMQ",
"SubName": "xx",
"AckTopic": "persistent://tenant/namespace/topic",
"ErrorMsg": "xx"
}
}
TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.
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. |
本页内容是否解决了您的问题?