Satnam Sandhu
Satnam Sandhu

Reputation: 680

AWS SQS returns 2 to 4 messages even after MaxNumberOfMessages parameter is set to 10 and queue has 13 messages

I have a standard AWS SQS with 13 messages. I wrote a simple JavaScript function to fetch 10 messages using long polling.

Here is the code:

 /* aws config */ 
 Poller.prototype.poll = async function() {
    let response;
    try{
      response = await this.SQS.receiveMessage({
        QueueUrl: "https://sqs.region.amazonaws.com/user_id/queue_name",
        MaxNumberOfMessages: 10,
        VisibilityTimeout: 20,
        WaitTimeSeconds: 20
      }).promise();
      return response;
    } catch(err) {
      console.log('its an error');
      /* handel error */
    }
  }

Every time i run this code it returns 2 messages and then 4 and this continues. I have tried messing with the WaitTimeSeconds and VisibilityTimeout but no use.

I am new to AWS SQS, thanks in advance. :)

Upvotes: 1

Views: 374

Answers (1)

E.J. Brennan
E.J. Brennan

Reputation: 46841

That is not unusual behavior - you are actually specifiying 'upto' 10 messages max, in my experience, unless a queue has lots of records (hundreds/thousands or more), than the small number returned is to be expected.

Upvotes: 2

Related Questions