0 votes
in AWS by

An application needs to make use of an SQS queue for working with messages. An SQS queue has been created with the default settings. The application needs 60 seconds to process each message. Which of the following step need to be carried out by the application?

1 Answer

0 votes
by

Answer - A.

If the SQS queue is created with the default settings, then the default visibility timeout is 30 seconds.

And since the application needs more time for processing, you first need to change the timeout and delete the message after it is processed.

Option B is incorrect since you need to process the message first.

Options C and D are incorrect since you need to change the visibility timeout for each message first.

For more information on SQS visibility timeout, please refer to the below URL-

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html

The correct answer is C: Process the message, change the visibility timeout. Delete the message.

When a message is pulled from an SQS queue, it becomes invisible to other consumers for a specified period known as the visibility timeout. During this time, the application has exclusive access to the message and can process it without worrying about other consumers modifying the message.

In this scenario, since it takes the application 60 seconds to process each message, the visibility timeout must be set to a value higher than 60 seconds to ensure that the message doesn't become visible to other consumers before the application is done processing it.

Here's the step-by-step explanation of the correct answer:

  1. The application pulls a message from the SQS queue.
  2. The visibility timeout for the message is changed to a value higher than 60 seconds (e.g., 120 seconds).
  3. The application processes the message for 60 seconds.
  4. If the message processing is successful, the application deletes the message from the SQS queue.
  5. If the message processing fails, the message will become visible to other consumers again after the visibility timeout expires, and another consumer can try to process it again.

Option A is incorrect because changing the visibility timeout for each message and then deleting it after processing is completed will result in the message becoming visible to other consumers before the application has finished processing it, which could result in the message being processed multiple times.

Option B is incorrect because deleting the message before changing the visibility timeout will result in the message becoming visible to other consumers before the application has finished processing it, which could result in the message being processed multiple times.

Option D is incorrect because deleting the message without changing the visibility timeout will result in the message becoming visible to other consumers immediately, which could result in the message being processed multiple times.

...