Soru

Zorluk: OrtaMessage-Based Integration using Amazon SQS and SNS

A developer is building a document conversion service where users upload files to be converted. The architecture uses an Amazon SQS queue to hold conversion tasks. A fleet of consumer instances running on Amazon ECS retrieves messages from the queue, processes the conversion (which takes up to 5 minutes per document), and then deletes the messages. During peak traffic, the developer notices that some documents are being processed multiple times by different container instances. Which two actions should the developer take to resolve this issue? (Select TWO)

  1. Increase the visibility timeout of the SQS queue to a value greater than 5 minutes.Cevap
  2. Ensure the consumer application code calls DeleteMessage using the receipt handle of the message after the conversion is complete.Cevap
  3. C
    Decrease the visibility timeout of the SQS queue to 1 minute to allow other container instances to quickly retry failed tasks.
  4. D
    Embed the AWS access keys directly within the container application code to authenticate SDK calls to SQS.
  5. E
    Increase the timeout of the AWS Lambda function that processes the queue to 15 minutes.

Cevap

The developer should increase the visibility timeout of the SQS queue to a value greater than 5 minutes, and ensure the consumer application code calls DeleteMessage using the receipt handle of the message after the conversion is complete.
The correct options are increasing the SQS queue's visibility timeout and ensuring the consumer code calls DeleteMessage after successful processing. Increasing the visibility timeout to exceed the maximum processing duration (5 minutes) ensures that the message remains hidden from other consumers while being processed. Deleting the message using the receipt handle after conversion is complete ensures it is removed from the queue and not processed again.

Adım Adım Çözüm

1
Analyze the message lifecycle and processing duration.
The document conversion task takes up to 5 minutes, but the SQS message becomes visible to other consumers before the conversion completes, leading to duplicate processing.
If the queue's visibility timeout is shorter than the processing time, SQS assumes the consumer failed and makes the message available to other consumers.
2
Adjust the SQS visibility timeout configuration.
Configure the SQS queue's visibility timeout to be greater than 5 minutes (e.g., 6 minutes).
This guarantees that no other consumer can retrieve the message while it is being actively processed by the first consumer.
3
Verify message deletion logic in the consumer code.
Ensure the application calls the SQS DeleteMessage API with the message's receipt handle once the task is finished.
Explicit deletion is required in SQS to permanently remove the message from the queue after successful processing, preventing it from reappearing.

Anahtar Kavram

SQS message visibility timeout and deletion lifecycle
Bu soruyu puanla