Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SQS only returning 1 message at a time

I'm getting the SQS queue with the following. But it always returns only 1 message. Based on the params below, I'm expecting 10 messages. This is not a FIFO queue.

Is there a different config parameter to bring back more than 1 message at a time?

const receiveParms = {
      QueueUrl: queueURL,
      MaxNumberOfMessages: 10,
      VisibilityTimeout: 15,
      WaitTimeSeconds: 20,
      AttributeNames: ["All"],
    };

    const receiveCommand = new ReceiveMessageCommand(receiveParms);
    const msgData = await sqsClient.send(receiveCommand);
like image 430
stack Avatar asked Oct 24 '25 06:10

stack


1 Answers

I have been trying to resolve this issue recently and have discovered a few details that help explain why SQS (non FIFO) behaves in this way.

MaxNumberOfMessages

The maximum number of messages to return. Amazon SQS never returns more messages than this value (however, fewer messages might be returned). Valid values: 1 to 10. Default: 1.

VisibilityTimeout

The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request.

WaitTimeSeconds

The duration (in seconds) for which the call waits for a message to arrive in the queue before returning. If a message is available, the call returns sooner than WaitTimeSeconds. If no messages are available and the wait time expires, the call returns successfully with an empty list of messages.


So if you have a single consumer and you want to get a specific message, then a way to do this is by repeat ReceiveMessage requests that utilise a VisibilityTimeout long enough to ensure that you only get different messages in each request.

Note, if you delete each message as it is received, then that makes things easier because you will only receive messages that are not deleted in subsequent requests. This is of course not ideal if there are multiple consumers of the same queue for the same message.

Even with all that said, you are still left with no guarantee that you will receive the messages you want in 1 or more requests.


So after all that, I was left with a redesign, just removing SQS from the equation and using a lambda to send information that otherwise would have been an SQS message, but stored in proper storage instead for retrieval and processing later.

Not exactly a solution, but a few work arounds and an alternative that may help.

like image 50
Jeremy Avatar answered Oct 25 '25 22:10

Jeremy



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!