Note:
This is a legacy API which has been hidden and will no longer be updated. We recommend using the new CMQ API 3.0 which is standardized and faster.
This API is used to consume a message in the queue.
Calling the ReceiveMessage
API will turn the status of the obtained message to inactive
, and the period of being inactive
is specified by the visibilityTimeout
queue attribute (for more information, please see CreateQueue API). After successful consumption within the period of visibilityTimeout
, you are recommended to call the (batch) DeleteMessage
API to delete the message; otherwise, it will return to the active
status and may be consumed again. This ensures that the message is consumed at least once, but cannot guarantee the idempotency. Therefore, deduplication logic is required at the business side.
https://cmq-queue-{$region}.api.qcloud.com
http://cmq-queue-{$region}.api.tencentyun.com
In the above domain names, {$region}
needs to be replaced with a specific region: gz
(Guangzhou), sh
(Shanghai), bj
(Beijing), hk
(Hong Kong (China)), cd
(Chengdu), ca
(North America), usw
(West US), or sg
(Singapore). The value of region
in the common parameters should be the same as that of region
in the domain name; otherwise, the latter will prevail, i.e., requests will be sent to the region as specified by region
in the domain name.
Note:
Whenever downstream traffic is generated from using the public domain name, traffic fees will be charged (even during the beta test period). Therefore, you are strongly recommended to use the private domain name as traffic fees will not be incurred there.
The list below contains only the API request parameters. Other parameters can be found in Common Request Parameters.
Parameter Name | Required | Type | Description |
---|---|---|---|
queueName | Yes | String | Queue name, which is unique under the same account in an individual region. It is a string of up to 64 characters, which must begin with a letter and can contain letters, digits, and dashes (- ). |
pollingWaitSeconds | No | Int | Long polling wait time in seconds. Value range: 0–30. If this parameter is not set, the value of pollingWaitSeconds in queue attributes will be used by default. |
Parameter Name | Type | Description |
---|---|---|
code | Int | 0: success; others: error. For more information on errors, please see Common Error Codes. |
message | String | Error message. |
requestId | String | Request ID generated by the server, which can be submitted to the backend for troubleshooting when an internal server error occurs. |
msgBody | String | Body of the consumed message. |
msgId | String | Unique ID of the consumed message. |
receiptHandle | String | Unique message handler returned from each consumption, which is used to delete the message. Only a message handler generated from the last consumption can be used to delete the message. After successful consumption within the period of visibilityTimeout , you can use the handler to call the (batch) DeleteMessage API to delete the message. If visibilityTimeout has elapsed, the handler will become invalid. |
enqueueTime | Int | Time when consumption is created and enters the queue. A Unix timestamp will be returned which is accurate down to the second. |
nextVisibleTime | Int | Time when a message is visible next time (i.e., consumable again). A Unix timestamp will be returned which is accurate down to the second. |
dequeueCount | Int | Reserved field. |
firstDequeueTime | Int | Reserved field. |
Please see Common Error Codes.
Input:
https://domain/v2/index.php?Action=ReceiveMessage &queueName=test-queue-123 &<Common Request Parameters>
Output:
{
"code" : 0,
"message" : "",
"requestId":"14534664555",
"msgBody":"helloworld1",
"msgId":"123345346",
"receiptHandle": "283748239349283",
"enqueueTime": 1462351990,
"firstDequeueTime": 1462352990,
"nextVisibleTime": 1462352999,
"dequeueCount": 2
}
本页内容是否解决了您的问题?