Κοινή χρήση μέσω


Get Messages

The Get Messages operation retrieves one or more messages from the front of the queue.

Request

The Get Messages request may be constructed as follows. We recommend that you use HTTPS. Replace myaccount with the name of your storage account, and replace myqueue with the name of your queue:

Method Request URI HTTP version
GET https://myaccount.queue.core.windows.net/myqueue/messages HTTP/1.1

Emulated storage service request

When you're making a request against the emulated storage service, specify the emulator hostname and the Azure Queue Storage port as 127.0.0.1:10001, followed by the emulated storage account name:

Method Request URI HTTP version
GET http://127.0.0.1:10001/devstoreaccount1/myqueue/messages HTTP/1.1

For more information, see Use the Azurite emulator for local Azure Storage development.

URI parameters

The following additional parameters may be specified on the request URI.

Parameter Description
numofmessages Optional. A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a maximum of 32. If fewer messages are visible, the visible messages are returned. By default, a single message is retrieved from the queue with this operation.
visibilitytimeout Optional. Specifies the new visibility time-out value, in seconds, relative to server time. The default value is 30 seconds.

A specified value must be larger than or equal to 1 second, and it can't be greater than 7 days, or greater than 2 hours on REST protocol versions that are earlier than 2011-08-18. The visibility time-out of a message can be set to a value later than the expiration time.
timeout Optional. The timeout parameter is expressed in seconds. For more information, see Set time-outs for Azure Queue Storage operations.

Request headers

The following table describes required and optional request headers.

Request header Description
Authorization Required. Specifies the authorization scheme, account name, and signature. For more information, see Authorize requests to Azure Storage.
Date or x-ms-date Required. Specifies the Coordinated Universal Time (UTC) for the request. For more information, see Authorize requests to Azure Storage.
x-ms-version Optional. Specifies the version of the operation to use for this request. For more information, see Versioning for the Azure Storage services.
x-ms-client-request-id Optional. Provides a client-generated, opaque value with a 1-kibibyte (KiB) character limit that's recorded in the logs when logging is configured. We highly recommend that you use this header to correlate client-side activities with requests that the server receives. For more information, see Monitor Azure Queue Storage.

Request body

None.

Response

The response includes an HTTP status code and a set of response headers.

Status code

A successful operation returns status code 200 (OK).

For more information about status codes, see Status and error codes.

Response headers

The response for this operation includes the following headers. The response may also include additional standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification.

Response header Description
x-ms-request-id Uniquely identifies the request that was made and can be used to troubleshoot the request. For more information, see Troubleshoot API operations.
x-ms-version Indicates the Azure Queue Storage version that was used to execute the request. This header is returned for requests that are made against version 2009-09-19 and later.
Date A UTC date/time value that's generated by the service, which indicates the time when the response was initiated.
x-ms-client-request-id Can be used to troubleshoot requests and corresponding responses. The value of this header is equal to the value of the x-ms-client-request-id header if it's present in the request and the value contains no more than 1,024 visible ASCII characters. If the x-ms-client-request-id header isn't present in the request, it won't be present in the response.

Response body

The response XML for the Get Messages operation is returned in the following format.

The MessageID element is a GUID value that identifies the message in the queue. This value is assigned to the message by Azure Queue Storage and is opaque to the client. You can use the value together with the value of the PopReceipt element to delete a message from the queue after you've retrieved it by using the Get Messages operation. The value of PopReceipt is also opaque to the client. Its only purpose is to ensure that a message can be deleted with the Delete Message operation.

The InsertionTime, ExpirationTime, and TimeNextVisible elements are represented as UTC values and formatted as described in RFC 1123.

The DequeueCount element has a value of 1 the first time the message is dequeued. This value is incremented each time the message is subsequently dequeued.

Note

The DequeueCount element is returned in the response body only if the queue was created by using Azure Queue Storage version 2009-09-19.

<QueueMessagesList>  
    <QueueMessage>  
      <MessageId>string-message-id</MessageId>  
      <InsertionTime>insertion-time</InsertionTime>  
      <ExpirationTime>expiration-time</ExpirationTime>  
      <PopReceipt>opaque-string-receipt-data</PopReceipt>  
      <TimeNextVisible>time-next-visible</TimeNextVisible>  
      <DequeueCount>integer</DequeueCount>  
      <MessageText>message-body</MessageText>  
    </QueueMessage>  
</QueueMessagesList>  

Sample response

Response Status:  
HTTP/1.1 200 OK  
Response Headers:  
Transfer-Encoding: chunked  
Content-Type: application/xml  
Date: Fri, 16 Sep 2011 21:04:30 GMT  
Server: Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0  
  
Response Body:  
<?xml version="1.0" encoding="utf-8"?>  
<QueueMessagesList>  
  <QueueMessage>  
    <MessageId>5974b586-0df3-4e2d-ad0c-18e3892bfca2</MessageId>  
    <InsertionTime>Fri, 09 Oct 2009 21:04:30 GMT</InsertionTime>  
    <ExpirationTime>Fri, 16 Oct 2009 21:04:30 GMT</ExpirationTime>  
    <PopReceipt>YzQ4Yzg1MDItYTc0Ny00OWNjLTkxYTUtZGM0MDFiZDAwYzEw</PopReceipt>  
    <TimeNextVisible>Fri, 09 Oct 2009 23:29:20 GMT</TimeNextVisible>  
    <DequeueCount>1</DequeueCount>  
    <MessageText>PHRlc3Q+dGhpcyBpcyBhIHRlc3QgbWVzc2FnZTwvdGVzdD4=</MessageText>  
  </QueueMessage>  
</QueueMessagesList>  

Authorization

This operation can be performed by the account owner and by anyone with a shared access signature that has permission to perform this operation.

Remarks

The message content is retrieved in the format that was used for the Put Message operation.

When a message is retrieved from the queue, the response includes the message and a pop receipt value, which is required to delete the message. The message isn't automatically deleted from the queue, but after it has been retrieved, it isn't visible to other clients for the time interval that's specified by the visibilitytimeout parameter.

If multiple messages are retrieved, each message has an associated pop receipt. The maximum number of messages that may be retrieved at the same time is 32.

The client that retrieves the message is expected to delete the message after it has been processed and before the time that's specified by the TimeNextVisible element of the response, which is calculated based on the value of the visibilitytimeout parameter. The value of visibilitytimeout is added to the time when the message is retrieved to determine the value of TimeNextVisible.

Because of clock skew, a message that's retrieved with a certain visibilitytimeout can reappear before that specified time-out has elapsed. Note that a client can infer that a message has already been dequeued by a different client based on the pop receipt, which is unique for each dequeuing of a message. If a client’s pop receipt no longer works to delete or update a message, and the client receives a 404 (Not Found) error, the message has been dequeued by another client.

Typically, when a consumer retrieves a message via Get Messages, that message is reserved for deletion until the visibilitytimeout interval expires. But this behavior isn't guaranteed. After the visibilitytimeout interval expires, the message again becomes visible to other consumers. If the message isn't subsequently retrieved and deleted by another consumer, the original consumer can delete the message by using the original pop receipt.

When a message is retrieved for the first time, its DequeueCount property is set to 1. If it isn't deleted and it's subsequently retrieved again, the DequeueCount property is incremented. The client may use this value to determine how many times a message has been retrieved.

If the visibilitytimeout or numofmessages parameter is out of range, the service returns status code 400 (Bad Request), along with additional error information, as shown in the following example.

  
HTTP/1.1 400 One of the query parameters specified in the request URI is outside the permissible range.  
Connection: Keep-Alive  
Content-Length: 455  
Via: 1.1 TK5-PRXY-22  
Date: Wed, 02 May 2012 19:37:23 GMT  
Content-Type: application/xml  
Server: Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0  
x-ms-request-id: 6a03526c-ca2c-4358-a63a-b5d096988533  
x-ms-version: 2011-08-18  
  
<?xml version="1.0" encoding="utf-8"?>  
   <Error>  
      <Code>OutOfRangeQueryParameterValue</Code>  
      <Message>One of the query parameters specified in the request URI is outside the permissible range.  
               RequestId:6a03526c-ca2c-4358-a63a-b5d096988533  
               Time:2012-05-02T19:37:24.2438463Z  
      </Message>  
     <QueryParameterName>numofmessages</QueryParameterName>  
     <QueryParameterValue>0</QueryParameterValue>  
     <MinimumAllowed>1</MinimumAllowed>  
     <MaximumAllowed>32</MaximumAllowed>  
   </Error>  
  

See also

Azure Queue Storage error codes
Authorize requests to Azure Storage
Status and error codes