Sending Messages in Batch

Last updated: 2019-07-05 12:24:09

PDF

1. API Description

This API (BatchSendMessage) is used to send a batch of messages (currently you can send up to 16) to the specified queue.

Domain for public network API request:cmq-queue-region.api.qcloud.com

Domain for private network API request:cmq-queue-region.api.tencentyun.com

At any time (including alpha test), any downstream traffic generated when using public network domain will incur traffic fee. It is strongly recommended that users on Tencent Cloud use private network domain, as it will not incur any traffic fee.

  • The "region" should be replaced by a specific region: gz (Guangzhou), sh (Shanghai), bj (Beijing). The "region" value in the common parameter should be kept consistent with that in the domain. In case of inconsistency, the one in the domain should prevail. The request should be sent to the region specified by the domain.
  • Requests for accessing via public network domain support both HTTP and HTTPS. Requests for accessing via private network only support HTTP.
  • Some of the input parameters are optional, so the default values are not required.
  • All output parameters will be returned to the user when the request is successful; otherwise, at least code, message, and requestId will be returned.

2. Input Parameters

The following request parameter list only provides API request parameters. For other parameters, refer to Common Request Parameters.

Parameter Name Required Type Description
queueName Yes String Queue name. This is unique under the same account in one region. The name of queue is a string with no more than 64 characters. It must start with letter, and the rest may contain letters, numbers and dashes (-).
msgBody.n Yes String Message body. One of the messages in the batch. Currently, there can be up to 16 messages in one message batch.

To make it more convenient for users, "n" may start from either 0 or 1, but is must be continuous. For example, if you send two messages, they can be (msgBody.0, msgBody.1) or (msgBody.1, msgBody.2).

Note: Currently the total size of all messages is limited to within 64 k (only the size of msgBody, message header and other parameters are not included), it is suggested to make a plan about how many messages to send in the batch beforehand.
delaySeconds No Int Time needed before the message becomes visible to user after it has been sent to the queue (in seconds). (This delay is effective to a batch of messages. Many-to-many mapping is not supported)
## 3. Output Parameters
Parameter Name Type Description
code Int 0: Succeeded, others: Error. For detailed errors, please refer to the table below.
message String Error message.
requestId String ID of the request generated by the server. When there is an internal error on the server, users can submit this ID to backend to locate the problem.
msgList Array List of unique IDs of the messages generated by the server. Each element is the information of one message.

msgList is defined as follows

Parameter Name Type Description
msgId String Unique ID of the message generated by the server.
Error Code Module Error Code Error Message Description
4400 10230 exceed maximum message size There's at least one message that reached the maximum message length limit. You can use the GetQueueAttributes API to view the maximum message length for the queue.
4000 10120 message body can't be empty The message body of msgBody cannot be empty. It should be at least 1 Byte.
4410 10240 reach maximum retention number of message The maximum number of messages in a queue has been reached. You can use the GetQueueAttributes API to view the maximum number of messages for the queue.
4470 10300 total message size exceed 64k The total size of all message bodies cannot exceed 64 k. For batch operation APIs, it is possible for the total size of all message bodies (msgBody only) to exceed 64 k. We established this limit in order to reduce network traffic load and ensure a good user experience for users. It is suggested to decrease the number of messages in the batch if you encountered this error.

Note: The error codes listed in the above table are specific to the API. If the error code you are looking for is not here, you may find it in the Common Error Codes.

4. Example

Input:

 https://domain/v2/index.php?Action=BatchSendMessage
 &queueName=test-queue-123
 &msgBody.1=helloworld1
 &msgBody.2=helloworld2
 &<Common request parameters>

Output:

{
"code" : 0,
"message" : "",
"requestId":"14534664555",
"msgList":
  [
    {
      "msgId":"123345346"
    },
    {
       "msgId":"456436346"
    }
  ]
}