AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.
Container for the parameters to the ReceiveMessage operation.
Retrieves one or more messages (up to 10), from the specified queue. Using the WaitTimeSeconds
parameter enables long-poll support. For more information, see Amazon
SQS Long Polling in the Amazon SQS Developer Guide.
Short poll is the default behavior where a weighted random set of machines is sampled
on a ReceiveMessage
call. Therefore, only the messages on the sampled machines
are returned. If the number of messages in the queue is small (fewer than 1,000),
you most likely get fewer messages than you requested per ReceiveMessage
call.
If the number of messages in the queue is extremely small, you might not receive any
messages in a particular ReceiveMessage
response. If this happens, repeat the
request.
For each message returned, the response includes the following:
The message body.
An MD5 digest of the message body. For information about MD5, see RFC1321.
The MessageId
you received when you sent the message to the queue.
The receipt handle.
The message attributes.
An MD5 digest of the message attributes.
The receipt handle is the identifier you must provide when deleting the message. For more information, see Queue and Message Identifiers in the Amazon SQS Developer Guide.
You can provide the VisibilityTimeout
parameter in your request. The parameter
is applied to the messages that Amazon SQS returns in the response. If you don't include
the parameter, the overall visibility timeout for the queue is used for the returned
messages. The default visibility timeout for a queue is 30 seconds.
In the future, new attributes might be added. If you write code that calls this action, we recommend that you structure your code so that it can handle new attributes gracefully.
Namespace: Amazon.SQS.Model
Assembly: AWSSDK.SQS.dll
Version: 3.x.y.z
public class ReceiveMessageRequest : AmazonSQSRequest IAmazonWebServiceRequest
The ReceiveMessageRequest type exposes the following members
Name | Description | |
---|---|---|
![]() |
ReceiveMessageRequest() |
Empty constructor used to set properties independently even when a simple constructor is available |
![]() |
ReceiveMessageRequest(string) |
Instantiates ReceiveMessageRequest with the parameterized properties |
Name | Type | Description | |
---|---|---|---|
![]() |
AttributeNames | System.Collections.Generic.List<System.String> |
Gets and sets the property AttributeNames.
This parameter has been discontinued but will be supported for backward compatibility.
To provide attribute names, you are encouraged to use A list of attributes that need to be returned along with each message. These attributes include:
|
![]() |
MaxNumberOfMessages | System.Int32 |
Gets and sets the property MaxNumberOfMessages. The maximum number of messages to return. Amazon SQS never returns more messages than this value (however, fewer messages might be returned). Valid values: 1 to 10. Default: 1. |
![]() |
MessageAttributeNames | System.Collections.Generic.List<System.String> |
Gets and sets the property MessageAttributeNames. The name of the message attribute, where N is the index.
When using |
![]() |
MessageSystemAttributeNames | System.Collections.Generic.List<System.String> |
Gets and sets the property MessageSystemAttributeNames. A list of attributes that need to be returned along with each message. These attributes include:
|
![]() |
QueueUrl | System.String |
Gets and sets the property QueueUrl. The URL of the Amazon SQS queue from which messages are received. Queue URLs and names are case-sensitive. |
![]() |
ReceiveRequestAttemptId | System.String |
Gets and sets the property ReceiveRequestAttemptId. This parameter applies only to FIFO (first-in-first-out) queues.
The token used for deduplication of
The maximum length of
For best practices of using |
![]() |
VisibilityTimeout | System.Int32 |
Gets and sets the property VisibilityTimeout.
The duration (in seconds) that the received messages are hidden from subsequent retrieve
requests after being retrieved by a
Understanding
For more information, see Visibility Timeout in the Amazon SQS Developer Guide. |
![]() |
WaitTimeSeconds | System.Int32 |
Gets and sets the property WaitTimeSeconds.
The duration (in seconds) for which the call waits for a message to arrive in the
queue before returning. If a message is available, the call returns sooner than
To avoid HTTP errors, ensure that the HTTP response timeout for |
This example shows how to receive a message.
var client = new AmazonSQSClient(); var request = new ReceiveMessageRequest { AttributeNames = new List<string>() { "All" }, MaxNumberOfMessages = 5, QueueUrl = "https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyTestQueue", VisibilityTimeout = (int)TimeSpan.FromMinutes(10).TotalSeconds, WaitTimeSeconds = (int)TimeSpan.FromSeconds(5).TotalSeconds }; var response = client.ReceiveMessage(request); if (response.Messages.Count > 0) { foreach (var message in response.Messages) { Console.WriteLine("For message ID '" + message.MessageId + "':"); Console.WriteLine(" Body: " + message.Body); Console.WriteLine(" Receipt handle: " + message.ReceiptHandle); Console.WriteLine(" MD5 of body: " + message.MD5OfBody); Console.WriteLine(" MD5 of message attributes: " + message.MD5OfMessageAttributes); Console.WriteLine(" Attributes:"); foreach (var attr in message.Attributes) { Console.WriteLine(" " + attr.Key + ": " + attr.Value); } } } else { Console.WriteLine("No messages received."); }
.NET:
Supported in: 8.0 and newer, Core 3.1
.NET Standard:
Supported in: 2.0
.NET Framework:
Supported in: 4.5 and newer, 3.5