[Yandex Cloud documentation](../../../index.md) > [Yandex Message Queue](../../index.md) > [API reference](../index.md) > Message > ReceiveMessage

# ReceiveMessage

Method for retrieving one or more messages (up to 10) from the specified queue. You can use the `WaitTimeSeconds` parameter to perform long-polling requests.

The method's standard behavior is short polling: it attempts to get messages from a single shard of the queue selected when calling `ReceiveMessage`. If the queue is short, fewer messages will be returned than specified in the `MaxNumberOfMessages` parameter. If the queue is too short, the response to your request may return zero messages, unless they were added to the queue shard. If you get zero messages, repeat your request.

If a new message arrives into an empty queue during an attempt to receive messages from it, it will be delayed by the duration of a single receive attempt.

The following parameters are returned for each of the received messages:

* `MessageId`: Message ID.
* `ReceiptHandle`: ID for deleting the received message or changing its [visibility timeout](../../concepts/visibility-timeout.md).
* `Body`: Message body.
* `MD5OfBody`: MD5 hash of the message body.
* `Attributes`: Set of message attributes indicating its sending time, the number of message receipts, and its delivery time.

When calling the method, you can provide the `VisibilityTimeout` parameter that will set visibility timeout for the incoming messages. If this parameter is missing, the messages will be assigned the visibility timeout set for the default queue.

When receiving messages from a FIFO queue, only one message will be accepted from a single message group per one `ReceiveMessage` call.

## Request {#request}

### Request parameters {#request-parameters}

Parameter | Type | Required<br>parameter | Description
----- | ----- | ----- | -----
`MaxNumberOfMessages` | **string** | No | Maximum number of messages that will be fetched. A smaller number of messages than specified in this parameter can be fetched, but never a higher number. Valid values: from 1 to 10. The default value is 1.
`MessageAttributeName.N` | **array** | No | Array of message attribute names to return in response to the request. A name may contain letters, numbers, hyphens, underscores, and periods. Attribute names are case-sensitive and unique within a single message. An attribute name cannot start or end with a period. Attribute names cannot contain several consecutive periods. The maximum length of an attribute name is 256 characters. You can get all attributes in one go by putting `All` or `.*` in your request. You can also use prefixes to get the necessary attributes.
`QueueUrl` | **string** | Yes | URL of the queue where the message is placed.
`ReceiveRequestAttemptId` | **string** | No | ID for a repeated attempt to receive messages from a FIFO queue. Learn more in [Deduplication](../../concepts/deduplication.md#request-attempts).
`VisibilityTimeout` | **string** | No | [Visibility timeout](../../concepts/visibility-timeout.md) of a message received.
`WaitTimeSeconds` | **string** | No | Waiting time in seconds for a message to be delivered to the queue. If messages arrive to the queue, the call will be made earlier than specified in`WaitTimeSeconds`. If no messages arrive within `WaitTimeSeconds`, an empty list will be returned.

#### Attributes {#attributes}

List of message attribute names. Attributes are provided in the `Attributes` parameter.

```text
Attribute.N.Name (attribute)
Attribute.N.Value (attribute value)
```

Attribute | Description
----- | -----
`All` | All values.
`ApproximateFirstReceiveTimestamp` | Time the message was received from the queue.
`ApproximateReceiveCount` | Number of times the message was received from the queue but not deleted.
`SenderId` | ID of the sender (IAM user).
`SentTimestamp` | Time the message was sent to the queue.
`MessageDeduplicationId` | ID of the token for message deduplication, used in FIFO queues. Each message must have a unique `MessageDeduplicationId`. If no `MessageDeduplicationId` is specified, the message will not be sent to a queue. The maximum length is 128 characters. You can use numbers, upper and lowercase Latin letters, and punctuation marks. Learn more in [Deduplication](../../concepts/deduplication.md).
`MessageGroupId` | ID of a message group, used in FIFO queues. Learn more in [Deduplication](../../concepts/deduplication.md).
`SequenceNumber` | Message number specific to FIFO queues within a group of messages with the same MessageGroupId.

## Response {#response}

### Successful response fields {#response-parameters}

Field | Type | Description
----- | ----- | -----
`Message` | **array** | [Message](../data-types/Message.md) array.

### ReceiveMessage errors {#errors}

For a list of errors common for all methods, see [Common errors](../common-errors.md).

HTTP code | Error ID | Description
----- | ----- | -----
403 | `OverLimit` | The operation has exceeded one of the [limits](../../concepts/limits.md).

## Request example {#request-example}

```text
Action=ReceiveMessage
&Version=2012-11-05
&QueueUrl=https://message-queue.api.cloud.yandex.net/b1g8ad42m6he********/dj6000000000********/sample-queue
&AttributeName.1=All
&MessageAttributeName.1=All
&VisibilityTimeout=15
```

For more on request formatting, see [General API request format](../index.md#api-request).

## Response example {#response-example}

```xml
<ReceiveMessageResponse>
    <ReceiveMessageResult>
        <Message>
            <MessageId>cddcbbe4-b0571f5c-d7b94ce4***-*****</MessageId>
            <ReceiptHandle>EAEgrOGOhogtKAA</ReceiptHandle>
            <MD5OfBody>3e25960a79dbc69b674cd4ec********</MD5OfBody>
            <Body>Hello world</Body>
            <Attribute>
                <Name>ApproximateFirstReceiveTimestamp</Name>
                <Value>1548348534956</Value>
            </Attribute>
            <Attribute>
                <Name>ApproximateReceiveCount</Name>
                <Value>1</Value>
            </Attribute>
            <Attribute>
                <Name>SentTimestamp</Name>
                <Value>1548347797419</Value>
            </Attribute>
        </Message>
    </ReceiveMessageResult>
    <ResponseMetadata>
        <RequestId>213c792a-2afa2234-4759dbc3-e5b8ef8-fc90fde14cdc1371b11d6453********</RequestId>
    </ResponseMetadata>
</ReceiveMessageResponse>
```