tencent cloud


Bulk consumption of messages

Last updated: 2021-04-12 15:02:16


    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.

    Interface description

    This API (BatchReceiveMessage) is used to consume multiple messages (up to 16 messages at present) in the queue.
    The length of time that the BatchReceiveMessage operation will change the status of the obtained message to inactive,inactive is specified by the Queue property visibilityTimeout see CreateQueue interface ). Consumers need to call API (batch) DeleteMessage to delete the message after successful consumption within visibilityTimeout time, otherwise the message will become active again and the message can be consumed again by consumers.

    • Domain name requested by public network API: https://cmq-queue-{$region}.api.qcloud.com
    • Domain name requested by private network API: http://cmq-queue-{$region}.api.tencentyun.com

    The above {$region} in the domain name needs to be replaced with a specific region : gz (Guangzhou), sh (Shanghai), bj (Beijing), shjr (Shanghai Financial), szjr (Shenzhen Financial), hk (China Hong Kong), cd (Chengdu), ca (North American), usw (Maxi), sg (Singapore). The region value in the common parameters should be consistent with the region value of the domain name. If there is any inconsistency, the request will be sent to the region specified by the domain name region based on the region value of the domain name.


    At any time (including during internal testing), if the public network downstream Traffic is generated by using a public network domain name, Traffic and cost will be charged. Therefore, users of the service on Tencent Cloud are strongly recommended to use it. Private network Domain name, private network will not produce Traffic cost.

    Input Parameter

    The following request parameter list only lists the API request parameters. For other parameters, please see Common Request Parameters page.

    Parameter name Required Type Description
    QueueName Yes String Queue name, which is unique under the same account in a single region. The queue name is a string of no more than 64 characters, must begin with a letter, and the rest can contain letters, numbers, and dashes (-).
    NumOfMsg Yes Int The number of messages consumed this time. The range of values is 1-16.
    PollingWaitSeconds No Int The long polling waiting time for this request. The value range is 0-30 seconds. If this parameter is not set, the pollingWaitSeconds value in the queue attribute is used by default.

    Output Parameter

    Parameter name Type Description
    Code Int 0: indicates success. Others: error. For more information, please see Common error code .
    Message String Error message.
    RequestId String Request ID generated by the server. When an internal error occurs on the server, the user can submit this ID to Backend Background to locate the problem.
    MsgInfoList Array A list of message information, with each element being the specific information of a message.

    MsgInfoList is defined as follows:

    Parameter name Type Description
    MsgBody String The message body of consumption.
    MsgId String The consumed message uniquely identifies the ID.
    ReceiptHandle String Each consumption returns a unique Message Handler, which is used to delete consumption. Only the handle generated by the last consumption of the message can be used to delete the message. And the validity period is visibilityTimeout, that is, the period of time for which hidden is taken out. After that time, the handle becomes invalid.
    EnqueueTime Int The time when consumption is produced and enters the queue. Returns Unix timestamp, accurate to seconds.
    FirstDequeueTime Int Reserved field.
    NextVisibleTime Int The next time the message is visible (can be consumed again). Returns Unix timestamp, accurate to seconds.
    DequeueCount Int Reserved field.

    Error Codes

    Please check Common error code .



    Https://domain/v2/index.php?Action=BatchReceiveMessage & queueName=test-queue-123 & numOfMsg=2 & <Common Request Parameters>


        "code": 0,
        "message": "",
        "requestId": "14534664555",
                "msgBody": "helloworld1",
                "msgId": "123345346",
                "receiptHandle": "283748239349283",
                "enqueueTime": 1462351990,
                "firstDequeueTime": 1462352990,
                "nextVisibleTime": 1462352999,
                "dequeueCount": 2
                "msgBody": "helloworld2",
                "msgId": "1233453456",
                "receiptHandle": "28374345763283",
                "enqueueTime": 1462351990,
                "firstDequeueTime": 1462352990,
                "nextVisibleTime": 1462352999,
                "dequeueCount": 2
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support