SQS Manager
, (*1)
SQS Manager is a library that simplifies fetching of messages from a SQS Queue. SQS Manager reads messages from the queue you want, prepares a SQSManager\Message object and pass it to function or method you define. The main advantages of this libray are:
- After the message has been depleted will be deleted from the queue by the Manager.
- If an exception is caught by the Manager, remaining messages will be released and the caught exception will be thrown.
- If the Manager retrieves several messages, it will pass them one by one to designed method/function. Afterwards the Manager will check VisibilityTimeout of remaining messages and in case of short expiry date, it will extend the expiration according to the VisibilityTimeout value. According to the AWS SQS documetation, the maximum timeout is 12 hours., (*2)
Installation
SQSManager can be installed by composer, (*3)
composer install dirk39/sqs-manager
Documentation
Usage of SQS Manager is very straightforward., (*4)
Construct
```php
require_once 'vendor/autoload.php';, (*5)
$manager = new SQSManager\Manager('AWS_APP_ID', 'AWS_APP_SECRET', 'AWS_REGION', $additional_conf);, (*6)
```
In $additional_conf array you can add custom configuration for the Aws\Sqs\SqsClient. You can find more information about additional conf here., (*7)
#### Fetch messages
```php, (*8)
...., (*9)
$manager->run($queueName, $callback, $listenerConfigs);, (*10)
```
- $queueName: the name of the queue you need to fetch. $queue could be the name of the queue or its url.
- $callback: $callback value will be passed to a call_user_func. Read the docs about acceptable $callback values. The Manager will pass a SQSManager\Message object to your callback function/method.
- $listenerConfigs: additional configs pass to Aws\Sqs\SqsClient::receiveMessage method. For further information about allowed configs read here, (*11)
Manager configurators
-
changeVisibilityTimeout: change default VisibilityTimeout value. It must be an integer between and 0 and 43200 seconds (i.e. 12 hours)
-
setWaitTimeSeconds: change default WaitTimeSeconds value. It must be an integer between and 1 and 20 seconds.
-
setMaxNumberOfMessages: change default MaxNumberOfMessages value. It must be an integer between and 1 and 10., (*12)
Testing
To replicate integration tests you have to copy tests/config.example.php into tests/configs.php and replace default values for AWS_KEY, AWS_SECRET, AWS_REGION, AWS_QUEUE_NAME with your values.
Important: AWS credentials must be of a user with read/write permission for Amazon SQS. At the end of the tests, designed queue will be purged of all messages so don't use production SQS queue!, (*13)