tencent cloud

Feedback

Batch Consuming Messages

Last updated: 2024-01-03 10:20:36

    API Description

    This API is used to consume up to 16 messages in a queue.
    Calling the BatchReceiveMessage API will change the status of the obtained message to inactive, and the period of being inactive is specified by the visibilityTimeout queue attribute (for more information, see CreateCmqQueue). We recommend you make the consumer call the (batch) DeleteMessage API to delete the message after it successfully consumes the message within the visibilityTimeout period; otherwise, the message will return to the active status and can be consumed again.
    The public/private domain names for API requests can be copied from Queue Service > API Request Address in the TDMQ for CMQ console. A sample address is as follows:
    Public network address: https://cmq-gz.publicXXX.tencenttdmq.com
    Private network address: http://gz.mqadapter.cmq.tencentyun.com
    Note:
    The API call URL varies by region.
    Whenever downstream traffic is generated from using the public domain name, traffic fees will be charged (even during the beta test period). Therefore, we strongly recommend you use the private domain name to avoid traffic fees.

    Input Parameters

    The list below contains only the API request parameters. Other parameters can be found in Common Request Parameters.
    Parameter
    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 (-).
    numOfMsg
    Yes
    Int
    Number of messages to be consumed. Value range: 1–16.
    pollingWaitSeconds
    No
    Int
    Long polling wait time in seconds. Value range: 0–30. If this parameter is not set, the value of the pollingWaitSeconds queue attribute will be used by default.

    Output Parameters

    Parameter
    Type
    Description
    code
    Int
    0: Success. others: Error. For more information, 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.
    msgInfoList
    Array
    Message information list. Each element indicates the information of one message.
    msgInfoList is defined as follows:
    Parameter
    Type
    Description
    msgBody
    String
    Body of the consumed message.
    msgId
    String
    Unique ID of the consumed message.
    receiptHandle
    String
    The unique message handler returned from each consumption, which is used to delete the message. Only the handler generated from the last consumption of a message can be used to delete the message. The validity period is visibilityTimeout, i.e., hidden duration of fetched message, after which 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.
    firstDequeueTime
    Int
    Reserved field.
    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.

    Error Codes

    For more information, see Common Error Codes.

    Samples

    Input:
    https://domain/v2/index.php?Action=BatchReceiveMessage &queueName=test-queue-123 &numOfMsg=2 &<<a href="">Common request parameters</a>>
    Output:
    {
    "code": 0,
    "message": "",
    "requestId": "14534664555",
    "msgInfoList":
    [
    {
    "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