Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the SQS ApproximateNumberOfMessages attribute include the delayed and not visible messages?

I'm currently in the process of using SQS from AWS. Every 60 seconds my application pulls all of the messages off the queue and processes them. Given that I can only retrieve up to 10 messages in a single request, I want to query the queue for the ApproximateNumberOfMessages. The aproximate number of messages in the queue determines how many times I need to call SQS in order to retrieve all of the messages in the queue.

When I query SQS for the queue attributes, I get:

{
  '$metadata': {
    httpStatusCode: 200,
    requestId: '...',
    extendedRequestId: undefined,
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  Attributes: {
    QueueArn: 'arn:...',
    ApproximateNumberOfMessages: '0',           <--- helpful
    ApproximateNumberOfMessagesNotVisible: '0', <--- is this attribute included in the `ApproximateNumberOfMessages`
    ApproximateNumberOfMessagesDelayed: '0',    <--- is this attribute included in the `ApproximateNumberOfMessages`
    CreatedTimestamp: '1641925448',
    LastModifiedTimestamp: '1641925448',
    VisibilityTimeout: '30',
    MaximumMessageSize: '262144',
    MessageRetentionPeriod: '345600',
    DelaySeconds: '90',
    RedrivePolicy: '{"deadLetterTargetArn":"arn:...","maxReceiveCount":4}',
    ReceiveMessageWaitTimeSeconds: '0',
    SqsManagedSseEnabled: 'false'
  }
}

As shown in the code block above, are ApproximateNumberOfMessagesNotVisible and ApproximateNumberOfMessagesDelayed included in the ApproximateNumberOfMessages value?

like image 321
kylejw2 Avatar asked Oct 24 '25 06:10

kylejw2


1 Answers

No they are not included. ApproximateNumberOfMessages is the number of messages currently available for retrieval:

The number of messages available for retrieval from the queue.

Also for Standard queue, these values are approximate only, and may not represent actual numbers of messages present:

For standard queues, the result is approximate because of the distributed architecture of Amazon SQS.

like image 120
Marcin Avatar answered Oct 25 '25 19:10

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!