roark
roark

Reputation: 830

Can I tell if an Amazon SQS message is still in flight?

Given an Amazon SQS message, is there a way to tell if it is still in flight via the API? Or, would I need to note the timestamp when I receive the message, subtract that from the current time, and check if that is less than the visibility timeout?

Upvotes: 10

Views: 6765

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269081

The normal flow for using Amazon Simple Queueing Service (SQS) is:

  • A message is pushed onto a queue using SendMessage (it can remain in the queue for up to 14 days)
  • An application uses ReceiveMessage to retrieve a message from the queue (no guarantee of first-in-first-out)
  • When the application has finished processing the message, it calls DeleteMessage (it can also call ChangeMessageVisibility to extend the time until it times-out)
  • If the application does not delete the message within a pre-configured time period, SQS makes the message reappear on the queue
  • If a message is retrieved from the queue more than a pre-configured number of times, the message can be moved to a Dead Letter queue

It is not possible to obtain information about a specific message. Rather, the application asks for a message (or a batch of messages), upon which the message becomes invisible (or 'in flight'). This also gives access to a ReceiptHandle that can be used with DeleteMessage or ChangeMessageVisibility.

The closest option is to call GetQueueAttributes. The value for ApproximateNumberOfMessagesNotVisible will indicate the number of in-flight messages but it will not give insight into a particular message.

Upvotes: 20

Related Questions