Search code examples
amazon-web-servicesaws-sdkamazon-sqs

AWS SQS always return 1 message (PHP SDK)


Im getting trouble with receiveMessage function of AWS SQS. It always returns 1 random message

        $result = $client->receiveMessage(array(
            'MaxNumberOfMessages' => 10,
            'MessageAttributeNames' => ['All'],
            'QueueUrl' => AConfig::sqs_query_url, // REQUIRED
            'WaitTimeSeconds' => 10,
        ));

Please give a suggestion :(

And one more question: Do have anyways to filter message by sender_id?

Thanks!


Solution

  • Its because of the nature of AWS SQS. Your messages are not physical in one single queue they are spreaded in different queues internally.

    Therefore the documentations says the following:

    [...] If the number of messages in the queue is small (fewer than 1,000), you most likely get fewer messages than you requested per ReceiveMessage call. [...]

    For more details please check the AWS SQS - Documentation.