Sends multiple messages to a queue at a time.

Name Value
API BatchSendMessage
Action mns:BatchSendMessage
Resource acs:mns:$region:$accountid:/queues/$queueName/messages

Description

You can call this operation to send a maximum of 16 messages to a queue at a time. The size of all messages that are sent at a time can be a maximum of 64 KB. If you do not specify the DelaySeconds parameter when you send a message to the queue, the message can be immediately consumed. If you want the message to be consumed on a regular basis, you can specify the DelaySeconds parameter when you send the message to the queue.

If you set the DelaySeconds parameter to a value that is greater than 0, the message is in the Delayed state after it is sent to the queue. The message cannot be consumed until the period that is specified by the DelaySeconds parameter ends and the message enters the Active state.

Note If the two values of the DelaySeconds parameter that is specified for the message and queue are different, the delay period specified for the message takes effect.

Request

Each request consists of the following parts:

  • Request line

    POST /queues/$queueName/messages HTTP/1.1

  • Operation-specific request headers

    None.

  • Request Body

    The request body is in the XML format. The body and parameters of multiple messages are included in the request body.

    Parameter Required Description Value
    MessageBody Yes The body of the message. UTF-8 character sets.
    DelaySeconds No The delay period after which the message sent to the queue can be consumed. Unit: seconds. Valid values: 0 to 604800 seconds. Data type: integer. Default value: 0.
    Priority No The priority of the message. A message with a higher priority can be consumed earlier. Valid values: 1 to 16. A smaller value indicates a higher priority. Default value: 8.

Response

Each response consists of the following parts:

  • HTTP Status Code

    HTTP/1.1 201 Created

  • Operation-specific response headers

    None.

  • Response Body

    The response is in the XML format. The MessageId and MessageBodyMD5 parameters of multiple messages are returned.

    Parameter Description
    MessageId The ID of the message. The message ID is unique in the queue.
    MessageBodyMD5 The MD5 hash of the message body.

Examples

Sample requests

POST /queues/$queueName/messages HTTP/1.1
Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
Date: Wed, 18 Mar 2012 12:00:00 GMT
Content-Length:500
Content-Type:text/xml;charset=utf-8
x-mns-version: 2015-06-06
Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXA****

<? xml version="1.0" encoding="UTF-8"? >
<Messages xmlns="http://mns.aliyuncs.com/doc/v1/">
    <Message>
        <MessageBody>Message1 Base64 Encoded Result</MessageBody>
        <DelaySeconds>60</DelaySeconds>
        <Priority>1</Priority>
    </Message>
    <Message>
        <MessageBody>Message2 Base64 Encoded Result</MessageBody>
        <DelaySeconds>60</DelaySeconds>
        <Priority>1</Priority>
    </Message>
</Messages>           

Sample responses

  • Sample success response if all messages are sent
        HTTP/1.1 201 Created
        Content-Length:120
        Content-Type:text/xml;charset=utf-8
        x-mns-request-id:512B2A634403E52B1956****
        x-mns-version: 2015-06-06
    
        <? xml version="1.0" encoding="UTF-8"? >
        <Messages xmlns="http://mns.aliyuncs.com/doc/v1/">
        <Message>
            <MessageId>5F290C926D472878-2-14D9529A8FA-20000****</MessageId>
            <MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6****</MessageBodyMD5>
        </Message>
        <Message>
            <MessageId>5F290C926D472878-2-14D9529A8FA-20000****</MessageId>
            <MessageBodyMD5>377AC5283D8765C9CEE4E0EA353D****</MessageBodyMD5>
        </Message>
        </Messages>                   
  • Sample response if some messages fail to be sent
        HTTP/1.1 500
        Content-Length:120
        Content-Type:text/xml;charset=utf-8
        x-mns-request-id:512B2A634403E52B1956****
        x-mns-version: 2015-06-06
    
        <? xml version="1.0" encoding="UTF-8"? >
        <Messages xmlns="http://mns.aliyuncs.com/doc/v1/">
        <Message>
            <MessageId>5F290C926D472878-2-14D9529A8FA-20000****</MessageId>
            <MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6****</MessageBodyMD5>
        </Message>
        <Message>
            <MessageId>5F290C926D472878-2-14D9529A8FA-20000****</MessageId>
            <MessageBodyMD5>377AC5283D8765C9CEE4E0EA353D****</MessageBodyMD5>
        </Message>
        <Message>
            <ErrorCode>InternalError</ErrorCode>
            <ErrorMessage>Internal error. </ErrorMessage>
        </Message>
        </Messages>              

Special error

Error code Error message HTTP status code
QueueNotExist The queue name you provided is not exist. 404
MalformedXML The XML you provided was not well-formed. 400
InvalidArgument The value of Element should between Low and High seconds/bytes. 400