Message related operations

Last Updated: Apr 05, 2017

SendMessage

Description

This interface is used to send a message to the specified message queue. A common message can be consumed by the consumer immediately after being sent to a message queue. The producer can set the DelaySeconds parameter when sending the message to consume later(the typical scenario is a scheduled task). The initial status of a message with the DelaySeconds value(>0) is Delayed. The message cannot be consumed till its status turns to Active after its DelaySeconds time expires in this status.

Tip:

The priority of the DelaySeconds parameter specified upon message sending is higher than the DelaySeconds attribute of the delayed message queue. That means, when the values of the two DelaySeconds attributes are different, the value of the DelaySeconds parameter specified upon message sending takes precedence.

Request

A request mainly includes the following parts:

  • Request line

    POST /queues/$queueName/messages HTTP/1.1

  • Special Request Header

    None. See Public Request Headers.

  • Request Body

    Request Body is in XML format. XML contains the attributes for creating message.

Parameter Name Description Parameter Value
MessageBody Required. Message body UTF-8 character set
DelaySeconds Optional. A delay time after which a message can be consumed, measured in seconds An integer between 0 and 604800 (7 days). The default value is 0
Priority Optional. Priority of a specified message.A message with a higher priority is more likely to be consumed earlier The value ranges from 1 to 16 (the value 1 indicates the highest priority). The default value is 8

Response

The returned message includes 3 parts: returned status line, HTTP header and message body.

  • HTTP Status Code

    HTTP/1.1 201 Created

  • Special Response Header

    None. See Public Returned Headers.

  • Response Body

    The returned result is in XML format. The MessageId and MessageBodyMD5 sub-elements of the message are returned.

Parameter Name Description
MessageId Message ID, which is unique in one queue.
MessageBodyMD5 MD5 value of the message body

Special Error

Error Code Error Message 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

Request example:

  1. POST /queues/$queueName/messages HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Wed, 18 Mar 2012 12:00:00 GMT
  4. Content-Length:500
  5. Content-Type:text/xml;charset=utf-8
  6. x-mns-version: 2015-06-06
  7. Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE
  8. <?xml version="1.0” encoding=”UTF-8” ?>
  9. <Message xmlns=”http://mns.aliyuncs.com/doc/v1/”>
  10. <MessageBody>Base64 Encoded Result</MessageBody>
  11. <DelaySeconds>60</DelaySeconds>
  12. <Priority>1</Priority>
  13. </Message>

Response example:

  1. HTTP/1.1 201Created
  2. Connnection:close
  3. Content-Length:120
  4. Content-Type:text/xml;charset=utf-8
  5. x-mns-request-id:512B2A634403E52B1956133E
  6. x-mns-version: 2015-06-06
  7. <?xml version="1.0” encoding=”UTF-8” ?>
  8. <Message xmlns=”http://mns.aliyuncs.com/doc/v1/”>
  9. <MessageId>
  10. 5F290C926D472878-2-14D9529A8FA-200000001
  11. </MessageId>
  12. <MessageBodyMD5>
  13. C5DD56A39F5F7BB8B3337C6D11B6D8C7
  14. </MessageBodyMD5>
  15. </Message>

BatchSendMessage

Description

This interface is used to send messages to the specified message queue in batches. A maximum of 16 messages can be sent in one BatchSendMessage operation.

A common message can be consumed by the consumer immediately after being sent to a message queue. The producer can set the DelaySeconds parameter when sending the message to consume later(the typical scenario is a scheduled task). The initial status of a message with the DelaySeconds value(>0) is Delayed. The message cannot be consumed till its status turns to Active after its DelaySeconds time expires In this status.

Tip:

The priority of the DelaySeconds parameter specified upon message sending is higher than the DelaySeconds attribute of the delayed message queue. That means, when the values of the two DelaySeconds attributes are different, the value of the DelaySeconds parameter specified upon message sending takes precedence.

Request

A request mainly includes the following parts:

  • Request line

    POST /queues/$queueName/messages HTTP/1.1

  • Special Request Header

    None. See Public Request Headers.

  • Request Body

    Request Body is in XML format. XML contains the attributes for creating messages.

Parameter Name Description Parameter Value
MessageBody Required. Message body UTF-8 character set
DelaySeconds Optional. A delay time after which a message can be consumed, measured in seconds An integer between 0 and 604800 (7 days). The default value is 0
Priority Optional. Priority of a specified message. A message with a higher priority is more likely to be consumed earlier The value ranges from 1 to 16 (the value 1 indicates the highest priority). The default value is 8

Response

The returned message includes 3 parts: returned status line, HTTP header and message body.

  • HTTP Status Code

    HTTP/1.1 201 Created

  • Special Response Header

    None. See Public Returned Headers.

  • Response Body

    The return result is in XML format. The MessageId and MessageBodyMD5 sub-elements of multiple messages are returned.

Parameter Name Description
MessageId Message ID, which is unique in one queue.
MessageBodyMD5 MD5 value of the message body

Special Error:

Error Code Error Message 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

Request example:

  1. POST /queues/$queueName/messages HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Wed, 18 Mar 2012 12:00:00 GMT
  4. Content-Length:500
  5. Content-Type:text/xml;charset=utf-8
  6. x-mns-version: 2015-06-06
  7. Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE
  8. <?xml version="1.0” encoding=”UTF-8” ?>
  9. <Messages xmlns=”http://mns.aliyuncs.com/doc/v1/”>
  10. <Message>
  11. <MessageBody>Message1 Base64 Encoded Result</MessageBody>
  12. <DelaySeconds>60</DelaySeconds>
  13. <Priority>1</Priority>
  14. </Message>
  15. <Message>
  16. <MessageBody>Message2 Base64 Encoded Result</MessageBody>
  17. <DelaySeconds>60</DelaySeconds>
  18. <Priority>1</Priority>
  19. </Message>
  20. </Messages>

Response example:

  1. HTTP/1.1 201Created
  2. Connnection:close
  3. Content-Length:120
  4. Content-Type:text/xml;charset=utf-8
  5. x-mns-request-id:512B2A634403E52B1956133E
  6. x-mns-version: 2015-06-06
  7. <?xml version="1.0” encoding=”UTF-8” ?>
  8. <Messages xmlns=”http://mns.aliyuncs.com/doc/v1/”>
  9. <Message>
  10. <MessageId>5F290C926D472878-2-14D9529A8FA-200000001</MessageId>
  11. <MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6D8C7</MessageBodyMD5>
  12. </Message>
  13. <Message>
  14. <MessageId>5F290C926D472878-2-14D9529A8FA-200000002</MessageId>
  15. <MessageBodyMD5>377AC5283D8765C9CEE4E0EA353DFC17</MessageBodyMD5>
  16. </Message>
  17. </Messages>

ReceiveMessage

Description

This interface is used by the consumer to consume a message in a message queue. The ReceiveMessage operation will change the acquired message to Inactive status. The Inactive duration is determined by the VisibilityTimeout attribute of the queue (for details, see “CreateQueue Interface”).

After the message is successfully consumed, the DeleteMessage interface should be called to delete the message in the VisibilityTimeout period. Otherwise, the message will be reset to Active status and consumable.

Request

A request mainly includes the following parts:

  • Request line

    GET /queues/$queueName/messages?waitseconds=10 HTTP/1.1

  • Special URI Parameter

Parameter Name Description Required?
waitseconds Maximum polling waiting time① of the ReceiveMessage request, measured in seconds Optional

Note:

If the ReceiveMessage request carries the waitseconds parameter, the polling waiting time of the ReceiveMessage request is specified by waitseconds. If the waitseconds parameter is not specified, the polling waiting time is specified by the PollingWaitSeconds attribute of the queue (see “CreateQueue Interface”).

  • Special Request Header

    None. See Public Request Headers.

  • Request Body

    None.

Response

The returned message includes 3 parts: returned status line, HTTP header and message body.

  • HTTP Status Code

    HTTP/1.1 200 OK

  • Special Response Header

    None. See Public Returned Headers.

  • Response Body

    The returned result is in XML format. The message body and attributes of the message are returned.

Parameter Name Description
MessageId Message ID, which is unique in one queue
ReceiptHandle Temporary handle generated for the acquired message, which is used to delete or modify the message in Inactive status and is valid before NextVisibleTime.
MessageBody Message body
MessageBodyMD5 MD5 value of the message body
EnqueueTime Time when a message is sent to the queue, represented in milliseconds that have elapsed since 1970-1-1 0:00
NextVisibleTime Time when a message can be consumed again, represented in milliseconds that have elapsed since 1970-1-1 0:00
FirstDequeueTime Time when a message is consumed for the first time, represented in milliseconds that have elapsed since 1970-1-1 0:00
DequeueCount Total consumption times of a message
Priority Priority of a message

Special Error

Error Code Error Message Status Code
QueueNotExist The queue name you provided is not exist. 404
MessageNotExist Message not exist. 404

Request example:

  1. GET /queues/$queueName/messages HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Wed, 28 May 2012 22:32:00 GMT
  4. x-mns-version: 2015-06-06
  5. Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE

Response example:

  1. HTTP/1.1 200 OK
  2. Connection:close
  3. Content-Type=text/xml;charset=utf-8
  4. Content-Length:500
  5. x-mns-request-id:512B2A634403E52B1956133E
  6. x-mns-version: 2015-06-06
  7. <?xml version="1.0” encoding=”UTF-8” ?>
  8. <Message xmlns=”http://mns.aliyuncs.com/doc/v1/”>
  9. <MessageId>5F290C926D472878-2-14D9529A8FA-200000001</MessageId>
  10. <ReceiptHandle>1-ODU4OTkzNDU5My0xNDMyNzI3ODI3LTItOA==</ReceiptHandle>
  11. <MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6D8C7</MessageBodyMD5>
  12. <MessageBody>This is a test message</MessageBody>
  13. <EnqueueTime>1250700979248</EnqueueTime>
  14. <NextVisibleTime>1250700799348</NextVisibleTime>
  15. <FirstDequeueTime>1250700779318</FirstDequeueTime >
  16. <DequeueCount>1</DequeueCount >
  17. <Priority>8</Priority>
  18. </Message>

BatchReceiveMessage

Description

This interface is used by the consumer to consume messages in a queue in batches. A maximum of 16 messages can be acquired in one BatchReceiveMessage operation.This operation will change the acquired messages to Inactive status. The Inactive duration is determined by the VisibilityTimeout attribute of the queue (for details, see “CreateQueue Interface”).

After the messages are successfully consumed, the DeleteMessage interface should be called to delete the acquired messages in the VisibilityTimeout period. Otherwise, the acquired messages will be reset to Active status and consumable again.

Request

A request mainly includes the following parts:

  • Request line

    GET /queues/$queueName/messages?numOfMessages=16&waitseconds=10 HTTP/1.1

  • Special URI Parameter

Parameter Name Description Required?
numOfMessages Maximum number of messages that can be acquired for the current BatchReceiveMessage operation. Required
waitseconds Maximum polling waiting time① of the ReceiveMessage request, measured in seconds. Optional

Note:

The polling waiting time of the BatchReceiveMessage request is specified by its preset waitseconds, or the PollingWaitSeconds attribute of the queue without presetting waitseconds (refer to “CreateQueue Interface”).

  • Special Request Header

    None. See “Public Request Headers”.

  • Request Body

    None.

Response

The returned message includes 3 parts: returned status line, HTTP header and message body.

  • HTTP Status Code

    HTTP/1.1 200 OK

  • Special Response Header

    None. See Public Returned Headers.

  • Response Body

    The return result is in XML format. The message bodies and attributes of multiple messages are returned.

Parameter Name Description
MessageId Message ID, which is unique in one queue
ReceiptHandle Temporary handle generated for the acquired message, which is used to delete or modify the message in Inactive status and is valid before NextVisibleTime.
MessageBody Message body
MessageBodyMD5 MD5 value of the message body
EnqueueTime Time when a message is sent to the queue, represented in milliseconds that have elapsed since 1970-1-1 0:00
NextVisibleTime Time when a message can be consumed again, represented in milliseconds that have elapsed since 1970-1-1 0:00
FirstDequeueTime Time when a message is consumed for the first time, represented in milliseconds that have elapsed since 1970-1-1 0:00
DequeueCount Total consumption times of a message
Priority Priority of a message

Special Error

Error Code Error Message Status Code
QueueNotExist The queue name you provided is not exist. 404
MessageNotExist Message not exist. 404

Request example:

  1. GET /queues/$queueName/messages?numOfMessages=16 HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Wed, 28 May 2012 22:32:00 GMT
  4. x-mns-version: 2015-06-06
  5. Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE

Response example:

  1. HTTP/1.1 200 OK
  2. Connection:close
  3. Content-Type=text/xml;charset=utf-8
  4. Content-Length:500
  5. x-mns-request-id:512B2A634403E52B1956133E
  6. x-mns-version: 2015-06-06
  7. <?xml version="1.0” encoding=”UTF-8” ?>
  8. <Messages xmlns=”http://mns.aliyuncs.com/doc/v1/”>
  9. <Message>
  10. <MessageId>5F290C926D472878-2-14D9529A8FA-200000001</MessageId>
  11. <ReceiptHandle>1-ODU4OTkzNDU5My0xNDMyNzI3ODI3LTItOA==</ReceiptHandle>
  12. <MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6D8C7</MessageBodyMD5>
  13. <MessageBody>This is a test message</MessageBody>
  14. <EnqueueTime>1250700979248</EnqueueTime>
  15. <NextVisibleTime>1250700799348</NextVisibleTime>
  16. <FirstDequeueTime>1250700779318</FirstDequeueTime >
  17. <DequeueCount>1</DequeueCount>
  18. <Priority>8</Priority>
  19. </Message>
  20. <Message>
  21. <ReceiptHandle>1-ODU4OTkzNDU5My0xNDMyNzI3MjQwLTEtOA==</ReceiptHandle>
  22. <MessageBodyMD5>C5DD56A39F5F7BB8B3337C6D11B6D8C7</MessageBodyMD5>
  23. <MessageBody>This is a test message</MessageBody>
  24. <EnqueueTime>1250700979252</EnqueueTime>
  25. <NextVisibleTime>1250700799350</NextVisibleTime>
  26. <FirstDequeueTime>1250700779330</FirstDequeueTime >
  27. <DequeueCount>1</DequeueCount>
  28. <Priority>8</Priority>
  29. </Message>
  30. </Messages>

DeleteMessage

Description

This interface is used to delete a consumed message. The consumer needs to use the ReceiptHandle returned by the previous consumption as the parameter to locate the message. This operation can be executed successfully only before NextVisibleTime.The ReceiptHandle becomes invalid as the messages turns to Active after the NextVisibleTime expires. You have to acquire a new ReceiptHandle again if you want to execute the deletion.

Request

A request mainly includes the following parts:

  • Request line

    DELETE /queues/$queueName/messages?ReceiptHandle=<receiptHandle> HTTP/1.1

  • Special URI Parameter

Parameter Name Description Required?
ReceiptHandle ReceiptHandle returned by the previous consumption. For details, see ReceiveMessage Interface. Required
  • Special Request Header

    None. See Public Request Headers.

  • Request Body

    None.

Response

The returned message includes 3 parts: returned status line, HTTP header and message body.

  • HTTP Status Code

    HTTP/1.1 204 NoContent

  • Special Response Header

    None. See Public Returned Headers.

  • Response Body

    None.

Special Error

Error Code Error Message Status Code
QueueNotExist The queue name you provided is not exist. 404
InvalidArgument The value of Element should between Low and High seconds/bytes. 400
ReceiptHandleError The receipt handle you provide is not valid. 400

Request example:

  1. DELETE /queues/$queueName/messages?ReceiptHandle=MbZj6wDWli+QEauMZc8ZRv37sIW2iJKq3M9Mx/KSbkJ0 HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Wed, 28 May 2012 22:32:00 GMT
  4. x-mns-version: 2015-06-06
  5. Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE

Response example:

  1. HTTP/1.1 204 NoContent
  2. x-mns-request-id:512B2A634403E52B1956133E
  3. x-mns-version: 2015-06-06

BatchDeleteMessage

Description

This interface is used to delete multiple messages at a maximum of 16 in a message queue in batches by inputting the corresponding ReceiptHandle for each.

This interface is recommended to used along with BatchReceiveMessage for higher efficiency.

The batch operation result may contain both successful and failed sub-requests.The HTTP status code is 204 only when all sub-requests are successful.If some sub-requests failed, you need to check the error information of every sub-request in the response.

Request

A request mainly includes the following parts:

  • Request line

    DELETE /queues/$queueName/messages HTTP/1.1

  • Special URI Parameter

    None.

  • Special Request Header

    None. See Public Request Headers.

  • Request Body

    Request Body is in XML format. XML contains the ReceiptHandles of multiple messages.

Response

The returned message includes 3 parts: returned status line, HTTP header and message body.

  • HTTP Status Code

    HTTP/1.1 204 NoContent

  • Special Response Header

    None. See Public Returned Headers.

  • Response Body

    None.

Special Error

Error Code Error Message Status Code
QueueNotExist The queue name you provided is not exist. 404
InvalidArgument The value of Element should between Low and High seconds/bytes. 400
ReceiptHandleError The receipt handle you provide is not valid. 400

Request example:

  1. DELETE /queues/$queueName/messages HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Wed, 28 May 2012 22:32:00 GMT
  4. x-mns-version: 2015-06-06
  5. Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE
  6. <?xml version="1.0” encoding=”UTF-8” ?>
  7. <ReceiptHandles xmlns=”http://mns.aliyuncs.com/doc/v1/”>
  8. <ReceiptHandle>1-ODU4OTkzNDU5My0xNDM1MTk3NjAwLTItNg==</ReceiptHandle>
  9. <ReceiptHandle>1-ODU4OTkzNDU5NC0xNDM1MTk3NjAwLTItNg==</ReceiptHandle>
  10. <ReceiptHandle>1-ODU4OTkzNDU5NS0xNDM1MTk3NjAwLTItNg==</ReceiptHandle>
  11. </ReceiptHandles>

Response example:

  • Delete all messages successful.

    1. HTTP/1.1 204 NoContent
    2. x-mns-request-id:512B2A634403E52B1956133E
    3. x-mns-version: 2015-06-06
  • Some messages failed to delete.

    1. HTTP/1.1 404
    2. Connection:close
    3. Content-Type=text/xml;charset=utf-8
    4. Content-Length:500
    5. x-mns-request-id:512B2A634403E52B1956133E
    6. x-mns-version: 2015-06-06
    7. <?xml version="1.0” encoding=”UTF-8” ?>
    8. <Errors xmlns=”http://mns.aliyuncs.com/doc/v1/”>
    9. <Error>
    10. <ErrorCode>MessageNotExist</ErrorCode>
    11. <ErrorMessage>Message not exist.</ErrorMessage>
    12. <ReceiptHandle>1-ODU4OTkzNDU5My0xNDM1MTk3NjAwLTItNg==</ReceiptHandle>
    13. </Error>
    14. <Error>
    15. <ErrorCode>MessageNotExist</ErrorCode>
    16. <ErrorMessage>Message not exist.</ErrorMessage>
    17. <ReceiptHandle>1-ODU4OTkzNDU5NC0xNDM1MTk3NjAwLTItNg==</ReceiptHandle>
    18. </Error>
    19. </Errors>

PeekMessage

Description

This interface is used by the consumer to view a message. Different from ReceiveMessage, PeekMessage does not change the message status. If the message is acquired by PeekMessage, the message is still in Active status and can be viewed or consumed. However, if the message is acquired by ReceiveMessage, the message changes to Inactive status and cannot be viewed or consumed within the VisibilityTimeout period.

Request

A request mainly includes the following parts:

  • Request line

    GET /queues/$queueName/messages?peekonly=true HTTP/1.1

  • URI parameter

    peekonly=true indicates that this request is used only to view the first message in the queue and will not change the message status

  • Special Request Header

    None. See Public Request Headers.

  • Request Body

    None.

Response

The returned message includes three parts: returned status line, HTTP header and message body.

  • HTTP Status Code

    HTTP/1.1 200 OK

  • Special Response Header

    None. See Public Returned Headers.

  • Response Body

    The return result is in XML format. The message body and attributes of the message are returned.

Parameter Name Description
MessageId Message ID, which is unique in one queue
MessageBody Message body
MessageBodyMD5 MD5 value of the message body
EnqueueTime Time when a message is sent to the queue, represented in milliseconds that have elapsed since 1970-1-1 0:00
FirstDequeueTime Time when a message is consumed for the first time, represented in milliseconds that have elapsed since 1970-1-1 0:00. If DequeueCount is 0, it is the same as EnqueueTime of the message
DequeueCount Total consumption times of a message
Priority Priority of a message

Special Error

Error Code Error Message Status Code
QueueNotExist The queue name you provided is not exist. 404
MessageNotExist Message not exist. 404

Request example:

  1. GET /queues/$queueName/messages?peekonly=true HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Wed, 28 May 2012 22:32:00 GMT
  4. x-mns-version: 2015-06-06
  5. Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE

Response example:

  1. HTTP/1.1 200 OK
  2. Connection:close
  3. Content-Type=text/xml;charset=utf-8
  4. Content-Length:500
  5. x-mns-request-id:512B2A634403E52B1956133E
  6. x-mns-version: 2015-06-06
  7. <?xml version="1.0" encoding="UTF-8"?>
  8. <Message xmlns=”http://mns.aliyuncs.com/doc/v1/”>
  9. <MessageId>D6D5F7C9C12D14A4-1-14D953EFC72-200000004</MessageId>
  10. <MessageBodyMD5>F9360F391579E71CA77BC5D50242FCF4</MessageBodyMD5>
  11. <MessageBody>This is a test message</MessageBody>
  12. <EnqueueTime>1250700979248</EnqueueTime>
  13. <FirstDequeueTime>1250700979348</FirstDequeueTime >
  14. <DequeueCount>5</DequeueCount>
  15. <Priority>8<Priority>
  16. </Message>

BatchPeekMessage

Description

This interface is used by the consumer to view messages in batches at a maximum of 16 at a time. Different from BatchReceiveMessage, BatchPeekMessage does not change the message status. If messages are acquired by BatchPeekMessage, the messages are still in Active status and can be viewed or consumed. However, if the messages are acquired by BatchReceiveMessage, the messages change to Inactive status and cannot be viewed or consumed within the VisibilityTimeout period.

Request

A request mainly includes the following parts:

  • Request line

    GET /queues/$queueName/messages?peekonly=true&numOfMessages=16 HTTP/1.1

  • Special URI Parameter

Parameter Name Description Required?
peekonly=true Indicates that this request is used only to view the first message in the queue and will not change the message status Required
numOfMessages Maximum number of messages that can be viewed for the current BatchPeekMessage operation Required
  • Special Request Header

    None. See Public Request Headers.

  • Request Body

    None.

Response

The returned message includes 3 parts: returned status line, HTTP header and message body.

  • HTTP Status Code

    HTTP/1.1 200 OK

  • Special Response Header

    None. See Public Returned Headers.

  • Response Body

    The return result is in XML format. The message bodies and attributes of multiple messages are returned.

Parameter Name Description
MessageId Message ID, which is unique in one queue
MessageBody Message body
MessageBodyMD5 MD5 value of the message body
EnqueueTime Time when a message is sent to the queue, represented in milliseconds that have elapsed since 1970-1-1 0:00
FirstDequeueTime Time when a message is consumed for the first time, represented in milliseconds that have elapsed since 1970-1-1 0:00. If DequeueCount is 0, it is the same as EnqueueTime of the message
DequeueCount Total consumption times of a message
Priority Priority of a message

Special Error

Error Code Error Message Status Code
QueueNotExist The queue name you provided is not exist. 404
MessageNotExist Message not exist. 404

Request example:

  1. GET /queues/$queueName/messages?peekonly=true&numOfMessages=16 HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Wed, 28 May 2012 22:32:00 GMT
  4. x-mns-version: 2015-06-06
  5. Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE

Response example:

  1. HTTP/1.1 200 OK
  2. Connection:close
  3. Content-Type=text/xml;charset=utf-8
  4. Content-Length:500
  5. x-mns-request-id:512B2A634403E52B1956133E
  6. x-mns-version: 2015-06-06
  7. <?xml version="1.0" encoding="UTF-8"?>
  8. <Messages xmlns=”http://mns.aliyuncs.com/doc/v1/”>
  9. <Message>
  10. <MessageId>D6D5F7C9C12D14A4-1-14D953EFC72-200000004</MessageId>
  11. <MessageBodyMD5>F9360F391579E71CA77BC5D50242FCF4</MessageBodyMD5>
  12. <MessageBody>This is a test message</MessageBody>
  13. <EnqueueTime>1250700979248</EnqueueTime>
  14. <FirstDequeueTime>1250700979348</FirstDequeueTime >
  15. <DequeueCount>5</DequeueCount>
  16. <Priority>8<Priority>
  17. </Message>
  18. <Message>
  19. <MessageId>D6D5F7C9C12D14A4-1-14D953EFC72-200000005</MessageId>
  20. <MessageBodyMD5>F9360F391579E71CA77BC5D50242FCF4</MessageBodyMD5>
  21. <MessageBody>This is a test message</MessageBody>
  22. <EnqueueTime>1250700979250</EnqueueTime>
  23. <FirstDequeueTime>1250700979352</FirstDequeueTime >
  24. <DequeueCount>5</DequeueCount>
  25. <Priority>8<Priority>
  26. </Message>
  27. </Messages>

ChangeMessageVisibility

Description

This interface is used to modify the next consumable time of a message which has been consumed and is still in Inactive status. After VisibilityTimeout of the message is modified successfully, a new ReceiptHandle is returned.

Request

A request mainly includes the following parts:

  • Request line

    PUT /queues/$queueName/messages?receiptHandle=<receiptHandle>&visibilityTimeout=<visibilitytimeout> HTTP/1.1

  • URI parameter

Parameter Name Description Required?
ReceiptHandle ReceiptHandle returned by the previous consumption. For details, see “ReceiveMessage Interface” Required
VisibilityTimeout Interval between the current time and the next consumable time, measured in seconds Required
  • Special Request Header

    None. See “Public Request Headers”.

  • Request Body

    None.

Response

The returned message includes 3 parts: returned status line, HTTP header and message body.

  • HTTP Status Code

    HTTP/1.1 200 OK

  • Special Response Header

    None. See Public Returned Headers.

  • Response Body

Parameter Name Description
ReceiptHandle Temporary handle returned after VisibilityTimeout of the message is modified, which is used to delete or modify the message in Inactive status and is valid before NextVisibleTime.
NextVisibleTime Time when a message can be consumed again, represented in milliseconds that have elapsed since 1970-1-1 0:00.

Special Error

Error Code Error Message Status Code
QueueNotExist The queue name you provided is not exist. 404
InvalidArgument The value of Element should between Low and High seconds/bytes. 400
MessageNotExist Message not exist. 404

Request example:

  1. PUT /queues/$queueName/messages
  2. ?receiptHandle=MbZj6wDWli+QEauMZc8ZRv37sIW2iJKq3M9Mx/KSbkJ0&visibilityTimeout=50 HTTP/1.1
  3. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  4. Date: Wed, 28 May 2012 22:32:00 GMT
  5. x-mns-version: 2015-06-06
  6. Authorization: MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE

Response example:

  1. HTTP/1.1 200OK
  2. x-mns-request-id:512B2A634403E52B1956133E
  3. x-mns-version: 2015-06-06
  4. <?xml version="1.0" encoding="UTF-8" ?>
  5. <Message xmlns="http://mns.aliyuncs.com/doc/v1/">
  6. <ReceiptHandle>
  7. TbZj6wDWli+9CEauMZc8ZRv37sIW2iJKq3M9Mx/TS1
  8. </ReceiptHandle >
  9. <NextVisibleTime>1250700979298000</NextVisibleTime>
  10. </Message>
Thank you! We've received your feedback.