Peek Messages

The Peek Messages operation retrieves one or more messages from the front of the queue, but it doesn't alter the visibility of the message.

Request

You can construct the Peek Messages request 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?peekonly=true HTTP/1.1

Emulated storage service request

When you're making a request against the emulated storage service, specify the emulator hostname and Queue service 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?peekonly=true HTTP/1.1

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

URI parameters

The following parameters may be specified on the request URI.

Parameter Description
numofmessages Optional. A nonzero integer value that specifies the number of messages to peek from the queue, up to a maximum of 32. By default, a single message is peeked from the queue with this operation.
timeout Optional. The timeout parameter is expressed in seconds. For more information, see Set time-outs for Queue service operations.

Request headers

The required and optional request headers are described in the following table:

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, a set of response headers, and an XML response body.

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 also includes 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 you can use it to troubleshoot the request. For more information, see Troubleshoot API operations.
x-ms-version The Queue service version that was used to execute the request. Returned for requests that were 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 their 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 Peek 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 the Queue service and is opaque to the client.

The InsertionTime and ExpirationTime 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 with Queue service version 2009-09-19.

<QueueMessagesList>  
    <QueueMessage>  
      <MessageId>string-message-id</MessageId>  
      <InsertionTime>insertion-time</InsertionTime>  
      <ExpirationTime>expiration-time</ExpirationTime>  
      <DequeueCount>integer</DequeueCount>  
      <MessageText>message-body</MessageText>  
    </QueueMessage>  
</QueueMessagesList>  

Note

This response differs from the response for the Get Messages operation in that it doesn't contain the PopReceipt or TimeNextVisible elements.

Sample response

Response Status:  
HTTP/1.1 200 OK  
  
Response Headers:  
Transfer-Encoding: chunked  
Content-Type: application/xml  
Date: Fri, 16 Sep 2011 22:51:18 GMT  
Server: Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0  
  
Response Body:  
<?xml version="1.0" encoding="utf-8"?>  
<QueueMessagesList>  
  <QueueMessage>  
    <MessageId>06eba214-8107-4412-a7f6-710a9baff647</MessageId>  
    <InsertionTime>Fri, 09 Oct 2009 18:59:54 GMT</InsertionTime>  
    <ExpirationTime>Fri, 16 Sep 2009 18:59:54 GMT</ExpirationTime>  
    <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 who has permission to perform this operation.

Remarks

When a message is retrieved from the queue with peekonly set to true, the visibility of the message is unchanged. The message remains available to other consumers of the queue until a client retrieves the message by using the Get Messages operation. The client that requests the message doesn't receive a pop receipt with the response and, therefore, can't delete the message.

Only messages that are visible can be retrieved with the Peek Messages operation. Note that the maximum number of messages that can be retrieved is 32.

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

Note

A call to Peek Messages doesn't increment the value of DequeueCount, but it returns this value for the client to read.

If the 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

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