All Products
Search
Document Center

Simple Message Queue (formerly MNS):BatchSendMessage

Last Updated:Mar 11, 2026

Sends up to 16 messages to a queue in a single request. The maximum total payload size per batch is 64 KB.

Authorization

By default, only Alibaba Cloud accounts can call this operation. Grant RAM users the required permissions before they call this operation. For more information, see Permission policies and examples.

Property

Value

API

BatchSendMessage

Action

mns:BatchSendMessage

Resource

acs:mns:$region:$accountid:/queues/$queueName/messages

Usage notes

  • Each batch supports up to 16 messages with a combined maximum size of 64 KB.

  • Base64-encode all message bodies before sending. This prevents errors caused by special characters in the XML payload.

  • If DelaySeconds is omitted or set to 0, messages become available for consumption immediately. To delay consumption, set DelaySeconds to a value greater than 0. Delayed messages enter the Delayed state and transition to Active after the specified period.

  • When both the message and the queue define DelaySeconds, the message-level value takes precedence.

  • QPS calculation: The effective QPS for a queue equals the request rate multiplied by the number of messages per batch. For example, 100 requests/second with 10 messages per batch results in 1,000 QPS on that queue.

Request

Request line

POST /queues/$queueName/messages HTTP/1.1

Headers

This operation does not define operation-specific request headers. For common headers, see the request example.

Request body

The request body uses XML format. Wrap each message in a <Message> element inside a <Messages> root element.

ParameterTypeRequiredDescription
MessageBodyStringYesThe message body. Base64-encode this value before sending.
DelaySecondsIntegerNoThe delay in seconds before the message becomes consumable. Valid values: 0 to 604800. Default: 0.

Response

Success

HTTP/1.1 201 Created

The response contains a <Message> element for each message in the batch:

ParameterTypeDescription
MessageIdStringThe unique message ID within the queue.
MessageBodyMD5StringThe MD5 hash of the message body. Compare this value against a locally computed hash to verify message integrity.

Partial failure

When some messages in a batch fail, the response returns HTTP status code 500. The response body contains a mix of successful and failed entries:

  • Successful messages include MessageId and MessageBodyMD5.

  • Failed messages include ErrorCode and ErrorMessage instead.

Examples

Send two messages with different delay values

Request:

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>This is test message 1.</MessageBody>
        <DelaySeconds>60</DelaySeconds>
        <Priority>1</Priority>
    </Message>
    <Message>
        <MessageBody>This is test message 2.</MessageBody>
        <DelaySeconds>0</DelaySeconds>
        <Priority>1</Priority>
    </Message>
</Messages>

Response: all messages 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>

Response: partial failure

When one or more messages fail, the response returns HTTP 500. Each <Message> element contains either a successful result or an error:

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>

Error codes

Error codeError messageHTTP statusDescription
QueueNotExistThe queue name you provided is not exist.404The specified queue does not exist. Create the queue before sending messages.
MalformedXMLThe XML you provided was not well-formed.400The request body contains invalid XML. Verify the XML structure and encoding.
InvalidArgumentThe value of Element should between Low and High seconds/bytes.400A parameter value is out of range. Specify a valid value as prompted.