The process of consuming messages from a queue depends on whether you use short or long polling. By default, Amazon SQS uses short polling, querying only a subset of its servers (based on a weighted random distribution) to determine whether any messages are available for a response. You can use long polling to reduce your costs while allowing your consumers to receive messages as soon as they arrive in the queue.
When you consume messages from a queue using short polling, Amazon SQS samples a subset of its servers (based on a weighted random distribution) and returns messages from only those servers. Thus, a particular ReceiveMessage request might not return all of your messages. However, if you have fewer than 1,000 messages in your queue, a subsequent request will return your messages. If you keep consuming from your queues, Amazon SQS samples all of its servers, and you receive all of your messages.
The following diagram shows the short-polling behavior of messages returned from a standard queue after one of your system components makes a receive request. Amazon SQS samples several of its servers (in gray) and returns messages A, C, D, and B from these servers. Message E isn't returned for this request but is returned for a subsequent request.
When the wait time for the ReceiveMessage
API action is greater than 0, long polling is in effect. The maximum long polling wait time is 20 seconds. Long polling helps reduce the cost of using Amazon SQS by eliminating the number of empty responses (when there are no messages available for a ReceiveMessage
request) and false empty responses (when messages are available but aren't included in a response).
Long polling occurs when the WaitTimeSeconds
parameter of a ReceiveMessage
request is set to a value greater than 0 in one of two ways:
The ReceiveMessage
call sets WaitTimeSeconds
to a value greater than 0.
The ReceiveMessage
call doesn’t set WaitTimeSeconds
, but the queue attribute ReceiveMessageWaitTimeSeconds
is set to a value greater than 0.
Therefore, the Developer should set the ReceiveMessage
API with a WaitTimeSeconds
of 20.
CORRECT: "Set the ReceiveMessage
API with a WaitTimeSeconds of 20" is the correct answer.
INCORRECT: "Set the SetQueueAttributes
API with a DelaySeconds
of 20" is incorrect as this would be used to configure a delay queue where the delivery of messages in the queue is delayed.
INCORRECT: "Set the ReceiveMessage
API with a VisibilityTimeout
of 30" is incorrect as this would configure the visibility timeout which is the length of time a message that has been received is invisible.
INCORRECT: "Set the SetQueueAttributes
with a MessageRetentionPeriod
of 60" is incorrect as this would configure how long messages are retained in the queue.
References:
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-short-and-long-polling.html
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SetQueueAttributes.html
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html
Save time with our AWS cheat sheets:
https://digitalcloud.training/aws-application-integration-services/