Soru

Zorluk: KolayMessage-Based Integration using Amazon SQS and SNS

An e-commerce application has a backend worker service running on Amazon EC2 instances that processes order fulfillment messages from an Amazon SQS standard queue. Each order takes approximately 25 seconds to process and complete. However, during testing, the developer observes that multiple EC2 instances are processing the same order message simultaneously. Which action should the developer take to resolve this duplication issue?

  1. A
    Decrease the Visibility Timeout of the Amazon SQS queue to a value less than 25 seconds.
  2. B
    Configure the worker application to initialize the AWS SDK client using hardcoded AWS access keys with higher privilege.
  3. Increase the Visibility Timeout of the Amazon SQS queue to a value greater than 25 seconds.Cevap
  4. D
    Decrease the execution timeout of the EC2 worker application components to less than 25 seconds.

Cevap

Increase the Visibility Timeout of the Amazon SQS queue to a value greater than 25 seconds.
Increasing the visibility timeout of the SQS queue beyond the processing time of 25 seconds prevents other worker instances from seeing and consuming the message while it is being actively processed. Once the worker finishes processing, it deletes the message, preventing duplicate processing altogether.

Adım Adım Çözüm

1
Analyze the cause of duplicate processing in SQS queues.
Duplicate processing occurs when a message's visibility timeout is shorter than the time it takes a consumer to process the message. The message becomes visible again in the queue before the first consumer can delete it.
Understanding the interaction between processing duration and visibility timeout is key to preventing redundant consumer operations.
2
Identify the message processing duration.
The scenario states that processing an order message takes approximately 25 seconds.
This establishes the minimum threshold for the visibility timeout duration.
3
Compare the processing duration with the SQS queue configurations.
Setting the visibility timeout to a value greater than 25 seconds ensures that the message remains invisible to other consumers until processing completes.
This allows the active consumer enough time to process and call DeleteMessage before any other consumer can retrieve it.

Anahtar Kavram

Amazon SQS Visibility Timeout

Alternatif Yöntem

The worker application can dynamically extend the visibility timeout of a specific message by calling the ChangeMessageVisibility API action if it detects that processing is taking longer than expected.
Tahmini Süre:1m 0s
Bu soruyu puanla