dirk39 / sqs-manager
Simple library that fetch and manage messages from SQS Queue
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 1
Open Issues: 0
pkg:composer/dirk39/sqs-manager
Requires
- aws/aws-sdk-php: dev-master
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2023-02-19 21:36:49 UTC
README
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
VisibilityTimeoutof remaining messages and in case of short expiry date, it will extend the expiration according to theVisibilityTimeoutvalue. According to the AWS SQS documetation, the maximum timeout is 12 hours.
Installation
SQSManager can be installed by composer
composer install dirk39/sqs-manager
Documentation
Usage of SQS Manager is very straightforward.
Construct
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.
Fetch messages
.... $manager->run($queueName, $callback, $listenerConfigs);
$queueName: the name of the queue you need to fetch.$queuecould 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\Messageobject to your callback function/method.$listenerConfigs: additional configs pass toAws\Sqs\SqsClient::receiveMessagemethod. For further information about allowed configs read here
Manager configurators
changeVisibilityTimeout: change defaultVisibilityTimeoutvalue. It must be an integer between and 0 and 43200 seconds (i.e. 12 hours)setWaitTimeSeconds: change defaultWaitTimeSecondsvalue. It must be an integer between and 1 and 20 seconds.setMaxNumberOfMessages: change defaultMaxNumberOfMessagesvalue. It must be an integer between and 1 and 10.
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!