All Products
Search
Document Center

Simple Message Queue (formerly MNS):SendMessage

Last Updated:Sep 02, 2024

Sends a message to a queue.

NameValue
APISendMessage
Actionmns:SendMessage
Resourceacs:mns:$region:$accountid:/queues/$queueName/messages

Description

You can call this operation to send a message to a queue. A standard message can be immediately consumed after the message is sent to the queue. If you do not want the message to be immediately consumed, you can specify the DelaySeconds parameter when you send the message. If you set the DelaySeconds parameter to a value that is greater than 0, the initial status of the message is Delayed after the message is sent to a queue. The message cannot be consumed until the period specified by the DelaySeconds parameter ends and the message changes to the Active state.

Note If 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 XML format. It contains the parameters of the message.

    ParameterRequiredDescriptionValue
    MessageBodyYesThe body of the message.UTF-8 characters.
    DelaySecondsNoThe delay period after which the message that is sent to the queue can be consumed. Unit: seconds.Valid values: 0 to 604800 seconds. Data type: integer. Default value: 0.
    PriorityNoThe priority of the message. A message with a higher priority can be consumed earlier.Valid values: 1 to 16. The value 1 indicates the highest 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 the message are returned.

    ParameterDescription
    MessageIdThe ID of the message. The message ID is unique in the queue.
    MessageBodyMD5The MD5 hash of the message body.
    ReceiptHandleThe receipt handle that was returned after the delayed message was received.

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"? >
<Message xmlns="http://mns.aliyuncs.com/doc/v1/">
    <MessageBody>Base64 Encoded Result</MessageBody>
    <DelaySeconds>60</DelaySeconds>
    <Priority>1</Priority>
</Message>            

Sample success responses

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"? >
<Message xmlns="http://mns.aliyuncs.com/doc/v1/">
<MessageId>5F290C926D472878-2-14D9529****-200000001</MessageId>
<MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6****</MessageBodyMD5>
<ReceiptHandle>1-ODU4OTkzNDU5My0xNDM1MTk3NjAwLTItNg==</ReceiptHandle>
</Message>           

Special error

Error codeError messageHTTP status code
QueueNotExistThe queue name you provided is not exist.404
MalformedXMLThe XML you provided was not well-formed.400
InvalidArgumentThe value of Element should between Low and High seconds/bytes.400