Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQS Messages Not Deleting

I have a small set of messages in an SQS queue, that are not deleted even though a deletion request sent to the AWS endpoint returns with a 200 response. The messages are processed by my application fine, and the deletion request is sent fine too.

I'm using the Java AWS SDK 1.3.6.

Has anyone else experienced this problem?

like image 394
EngineerBetter_DJ Avatar asked Apr 17 '12 15:04

EngineerBetter_DJ


People also ask

How do I delete a message from AN SQS queue?

To select the message to delete, use the ReceiptHandle of the message (not the MessageId which you receive when you send the message). Amazon SQS can delete a message from a queue even if a visibility timeout setting causes the message to be locked by another consumer.

Why doesn't Amazon SQS automatically delete a message after retrieve?

Amazon SQS doesn't automatically delete a message after retrieving it for you, in case you don't successfully receive the message (for example, if the consumers fail or you lose connectivity). To delete a message, you must send a separate request which acknowledges that you've successfully received and processed the message.

Why does my Amazon SQS queue show an empty response?

Because Amazon SQS is a distributed system, a queue with very few messages might display an empty response to a receive request. In this case, rerun the request to get your message. Depending on your application's needs, you might have to use short or long polling to receive messages.

How do I delete a message from an amazonsqs queue?

Messages are returned as a list of Message objects. After receiving a message and processing its contents, delete the message from the queue by sending the message’s receipt handle and queue URL to the AmazonSQS client’s deleteMessage method. See the complete example on GitHub.


Video Answer


2 Answers

Whoops - the queue was accidentally set to defaultVisibilityTimeout=0. Changing this to a positive value fixed the problem.

This still raises a few questions though:

  1. Why did this only affect some messages? Perhaps some took longer to process?
  2. Why did Amazon return a 200 for delete when the messages weren't being deleted?
  3. Was the deletion failing because it fell outside of the 0-second window (in which case why did any deletion requests succeed?), or did they fail because another consumer had picked them up by the time the deletion request was received?
like image 145
EngineerBetter_DJ Avatar answered Oct 20 '22 07:10

EngineerBetter_DJ


Official documentation (version 1.9.13)

IMPORTANT: It is possible you will receive a message even after you have deleted it. This might happen on rare occasions if one of the servers storing a copy of the message is unavailable when you request to delete the message. The copy remains on the server and might be returned to you again on a subsequent receive request. You should create your system to be idempotent so that receiving a particular message more than once is not a problem.

like image 31
Ravindranath Akila Avatar answered Oct 20 '22 05:10

Ravindranath Akila