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.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 parameters
Parameter | Type | Required 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. For more information, see Deduplication. |
VisibilityTimeout |
string | No | Visibility timeout 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 inWaitTimeSeconds . If no messages arrive within WaitTimeSeconds , an empty list will be returned. |
Attributes
List of message attribute names. Attributes are provided in the Attributes
parameter.
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. For more information, see Deduplication. |
MessageGroupId |
ID of a message group, used in FIFO queues. For more information, see Deduplication. |
SequenceNumber |
Message number specific to FIFO queues within a group of messages with the same MessageGroupId. |
Response
Successful response fields
Field | Type | Description |
---|---|---|
Message |
array | Message array. |
ReceiveMessage errors
For a list of errors common for all methods, see Common errors.
HTTP code | Error ID | Description |
---|---|---|
403 | OverLimit |
The operation has exceeded one of the limits. |
Sample request
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 information about forming requests, see General API request format.
Response example
<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>