Retrieves one or more messages from the specified queue, including the message body and message
ID of each message. Messages returned by this action stay in the queue until you delete them.
However, once a message is returned to a ReceiveMessage
request, it is not
returned on subsequent ReceiveMessage
requests for the duration of the
VisibilityTimeout
. If you do not specify a VisibilityTimeout
in the
request, the overall visibility timeout for the queue is used for the returned messages.
If a message is available in the queue, the call will return immediately. Otherwise, it will
wait up to WaitTimeSeconds
for a message to arrive. If you do not specify
WaitTimeSeconds
in the request, the queue attribute ReceiveMessageWaitTimeSeconds
is used to determine how long to wait.
You could ask for additional information about each message through the attributes. Attributes
that can be requested are [SenderId, ApproximateFirstReceiveTimestamp,
ApproximateReceiveCount, SentTimestamp]
.
Access
public
Parameters
Parameter |
Type |
Required |
Description |
---|---|---|---|
|
Required |
The URL of the SQS queue to take action on. |
|
|
Optional |
An associative array of parameters that can have the following keys:
|
Returns
Type |
Description |
---|---|
A |
Examples
Receive a message from the queue.
// Receive a message $sqs = new AmazonSQS(); $response = $sqs->receive_message('example-queue'); // Success? var_dump($response->isOK());Result:
bool(true)
Receive a message from the queue and increase the visibility timeout.
// Receive a message, and allow more time to process $sqs = new AmazonSQS(); $response = $sqs->receive_message('example-queue', array( 'VisibilityTimeout' => 7200 )); // Success? var_dump($response->isOK());Result:
bool(true)
Receive a message from the queue, with multiple attributes.
// Receive a single message $sqs = new AmazonSQS(); $response = $sqs->receive_message('example-queue', array( 'AttributeName' => array( 'SenderId', 'SentTimestamp' ) )); // Success? var_dump($response->isOK());Result:
bool(true)
Related Methods
Source
Method defined in services/sqs.class.php | Toggle source view (16 lines) | View on GitHub