yii-aws-sqs
AWS Simple Queue Service component for the yii framework version 0.1 and AWS SDK version 3.
##Requirements
##Installation Get a copy extensions on your codebase, preferably added a git submodule with the following way:
$ git submodule add https://github.com/PeoplePerHour/yii-aws-sqs.git extensions/yii-aws-sqs
Copy file under extensions ( or folder of your choice ) and import it in your config file
<?php
return array(
...
'import' => array(
...
'ext.yii-aws-sqs.*',
...
),
...
);
Also, config component in your config file:
<?php
return array(
...
'components' => array(
...
'sqs' => array(
'class' => 'AWSQueueManager',//'ext.yii-aws-sqs.AWSQueueManager' if not imported
'accessKey' => 'Access Key Id',
'secretKey' => 'Secret Key Id',
)
),
...
);
Install the Amazon SDK for PHP 2 and ensure the autoloader is in your index.php
. For example if you installed the SDK using composer, in your index.php
you'd have:
<?php
...
// Autoload the libraries included by composer (e.g. AWS SDK v2)
include_once __DIR__.'/../vendor/autoload.php';
...
?>
##Running test
In order you want to run test:
- Access your test folder in your yii application. Usually
/var/www/html/myproject/tests/
- Define your SQS access & secret key in your
bootstrap.php
like:
<?php
....
define('SQS_ACCESS_KEY', 'KJGVJRHJ24v...');
define('SQS_SECRET_KEY', '6p2dnWQF3g1...');
...
?>
- Run the test. Example:
phpunit ../extensions/yii-aws-sqs/tests/unit/
##Examples
###Queues
In order to get a list of queues access the property AWSQueueManager::$queues
like
<?php
//This will trigger a request to SQS the first time it is called & will return AWSQueueList object.
$myAwsQueues = Yii::app()->queues;
//In order to refresh use the `$refresh` param;
$myAwsQueues = Yii::app()->getQueues(true);
A queue can be accessed either from the queues object either from the sqs object. Like:
<?php
Yii::app()->sqs->queues->myTestQueue; // is equal to
Yii::app()->sqs->myTestQueue;
Creating a queue is easy
<?php
if(($newQueue=Yii::app()->sqs->create('myTestingQueue'))!==null) {
$newQueue->send('message');//Sending a message, see later for instructions
}