本文整理汇总了PHP中Aws\Sqs\SqsClient::getCommand方法的典型用法代码示例。如果您正苦于以下问题:PHP SqsClient::getCommand方法的具体用法?PHP SqsClient::getCommand怎么用?PHP SqsClient::getCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aws\Sqs\SqsClient
的用法示例。
在下文中一共展示了SqsClient::getCommand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBasicOperations
public function testBasicOperations()
{
// Create a queue and make sure everything goes OK
$queueName = 'php-integ-sqs-queue-' . time();
self::log('Create an SQS queue.');
$result = $this->sqs->getCommand('CreateQueue', array('QueueName' => $queueName, 'Attributes' => array(QueueAttribute::RECEIVE_MESSAGE_WAIT_TIME_SECONDS => 20, QueueAttribute::DELAY_SECONDS => 10)))->getResult();
$createdQueueUrl = $result->get('QueueUrl');
self::log('Get the queue URL.');
do {
try {
$result = $this->sqs->getCommand('GetQueueUrl', array('QueueName' => $queueName))->getResult();
$queueUrl = $result->get('QueueUrl');
} catch (SqsException $e) {
$queueUrl = null;
sleep(2);
}
} while (!$queueUrl);
$this->assertEquals($createdQueueUrl, $queueUrl);
self::log('Get the queue attributes.');
$result = $this->sqs->getCommand('GetQueueAttributes', array('QueueUrl' => $queueUrl, 'AttributeNames' => array(QueueAttribute::ALL)))->getResult();
$this->assertEquals(20, $result->getPath('Attributes/' . QueueAttribute::RECEIVE_MESSAGE_WAIT_TIME_SECONDS));
$this->assertEquals(10, $result->getPath('Attributes/' . QueueAttribute::DELAY_SECONDS));
self::log('Make sure the custom ARN-calculating logic returns the actual ARN.');
$this->assertEquals($this->sqs->getQueueArn($queueUrl), $result->getPath('Attributes/' . QueueAttribute::QUEUE_ARN));
// Send, receive, and delete messages
$messagesToDelete = array();
self::log('Send a message with no delay to the queue.');
$this->sqs->getCommand('SendMessage', array('QueueUrl' => $queueUrl, 'MessageBody' => 'test message 1', 'DelaySeconds' => 0, 'VisibilityTimeout' => 300))->execute();
self::log('Receive a message from the queue.');
$result = $this->sqs->getCommand('ReceiveMessage', array('QueueUrl' => $queueUrl, 'AttributeNames' => array(MessageAttribute::ALL)))->getResult();
$messages = $result->get('Messages');
$this->assertCount(1, $messages);
$message = $messages[0];
$this->assertEquals('test message 1', $message['Body']);
$this->assertCount(4, $message['Attributes']);
// Make sure attributes are unmarshalled correctly
$messagesToDelete[] = array('Id' => str_replace(' ', '-', $message['Body']), 'ReceiptHandle' => $message['ReceiptHandle']);
self::log('Send and receive a delayed message and make sure long polling is working. Please wait.');
$startTime = microtime(true);
$this->sqs->getCommand('SendMessage', array('QueueUrl' => $queueUrl, 'MessageBody' => 'test message 2'))->execute();
$result = $this->sqs->getCommand('ReceiveMessage', array('QueueUrl' => $queueUrl))->getResult();
$endTime = microtime(true);
$this->assertGreaterThan(5, $endTime - $startTime);
$this->assertGreaterThanOrEqual(1, count($result->get('Messages')));
$message = $result->getPath('Messages/0');
$messagesToDelete[] = array('Id' => str_replace(' ', '-', $message['Body']), 'ReceiptHandle' => $message['ReceiptHandle']);
self::log('Delete the messages using batch delete and verify that the deletions are successful.');
$result = $this->sqs->getCommand('DeleteMessageBatch', array('QueueUrl' => $queueUrl, 'Entries' => $messagesToDelete))->getResult();
$deletions = $result['Successful'];
$this->assertCount(2, $deletions);
foreach ($deletions as $deletion) {
$this->assertRegExp('/^test\\-message\\-\\d$/', $deletion['Id']);
}
// Delete the queue
self::log('Delete the queue.');
$this->sqs->getCommand('DeleteQueue', array('QueueUrl' => $queueUrl))->execute();
}