mrehman23 / aws-sqs
PHP package for interacting with Amazon Simple Queue Service (SQS)
Installs: 2 541
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.2
- aws/aws-sdk-php: ^3.0
README
This package provides a simple and convenient way to interact with Amazon Simple Queue Service (SQS) using PHP.
Features
- Send messages to an SQS queue.
- Receive messages from an SQS queue.
- Delete messages from an SQS queue.
Requirements
- PHP 7.2 or later
- AWS SDK for PHP (aws/aws-sdk-php)
- AWS account credentials set up (Access Key ID and Secret Access Key)
Installation
You can install this package via Composer:
composer require mrehman23/aws-sqs
Examples
require 'vendor/autoload.php';
use AwsSqs\SqsMessenger;
$AwsConfig = [
'AWS_KEY'=>'', //You should put your AWS_KEY
'AWS_SECRET_KEY'=>'', //You should put your AWS_SECRET_KEY
'AWS_REGION'=>'eu-west-1', //You should put your AWS_REGION
'API_VERSION'=>'2012-11-05'
];
$messenger = new SqsMessenger($AwsConfig);
// $messenger->RetryTimesOnFail = 2;
// $messenger->WaitBeforeRetry = 1; //seconds
$queue = "<Your queueUrl>";
$message = "This is a message for SQS";
$messageAttributes['params'] = [
'DataType' => 'String',
'StringValue' => json_encode($params)
];
$delaySeconds = 10;
$messageGroupId = '';
$messageDeduplicationId = '';
$result = $messenger->publish($queue, $message, $messageAttributes, $delaySeconds, $messageGroupId, $messageDeduplicationId);
Listener
require 'vendor/autoload.php';
use AwsSqs\SqsWorker;
$worker = new SqsWorker($this->awsConfig['credentials']);
$worker->listen(
$this->awsConfig['queue'],
[$this, 'processMessage'],
[$this, 'errorHandler']
);