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 theVisibilityTimeout
value. According to the AWS SQS documetation, the maximum timeout is 12 hours.
SQSManager can be installed by composer
composer install dirk39/sqs-manager
Usage of SQS Manager is very straightforward.
require_once 'vendor/autoload.php';
$manager = new SQSManager\Manager('AWS_APP_ID', 'AWS_APP_SECRET', 'AWS_REGION', $additional_conf);
In $additional_conf
array you can add custom configuration for the Aws\Sqs\SqsClient
. You can find more information about additional conf here.
....
$manager->run($queueName, $callback, $listenerConfigs);
$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 acall_user_func
. Read the docs about acceptable $callback values. The Manager will pass aSQSManager\Message
object to your callback function/method.$listenerConfigs
: additional configs pass toAws\Sqs\SqsClient::receiveMessage
method. For further information about allowed configs read here
changeVisibilityTimeout
: change defaultVisibilityTimeout
value. It must be an integer between and 0 and 43200 seconds (i.e. 12 hours)setWaitTimeSeconds
: change defaultWaitTimeSeconds
value. It must be an integer between and 1 and 20 seconds.setMaxNumberOfMessages
: change defaultMaxNumberOfMessages
value. It must be an integer between and 1 and 10.
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!