A transport for Amazon SQS broker. It uses internally official aws sdk library
- Installation
- Create context
- Declare queue
- Send message to queue
- Send delay message
- Consume message
- Purge queue messages
$ composer require enqueue/sqs
<?php
use Enqueue\Sqs\SqsConnectionFactory;
$factory = new SqsConnectionFactory([
'key' => 'aKey',
'secret' => 'aSecret',
'region' => 'aRegion',
]);
// same as above but given as DSN string
$factory = new SqsConnectionFactory('sqs:?key=aKey&secret=aSecret®ion=aRegion');
$psrContext = $factory->createContext();
// if you have enqueue/enqueue library installed you can use a function from there to create the context
$psrContext = \Enqueue\dsn_to_context('sqs:');
Declare queue operation creates a queue on a broker side.
<?php
/** @var \Enqueue\Sqs\SqsContext $psrContext */
$fooQueue = $psrContext->createQueue('foo');
$psrContext->declareQueue($fooQueue);
// to remove queue use deleteQueue method
//$psrContext->deleteQueue($fooQueue);
<?php
/** @var \Enqueue\Sqs\SqsContext $psrContext */
$fooQueue = $psrContext->createQueue('foo');
$message = $psrContext->createMessage('Hello world!');
$psrContext->createProducer()->send($fooQueue, $message);
<?php
/** @var \Enqueue\Sqs\SqsContext $psrContext */
$fooQueue = $psrContext->createQueue('foo');
$message = $psrContext->createMessage('Hello world!');
$psrContext->createProducer()
->setDeliveryDelay(60000) // 60 sec
->send($fooQueue, $message)
;
<?php
/** @var \Enqueue\Sqs\SqsContext $psrContext */
$fooQueue = $psrContext->createQueue('foo');
$consumer = $psrContext->createConsumer($fooQueue);
$message = $consumer->receive();
// process a message
$consumer->acknowledge($message);
// $consumer->reject($message);
<?php
/** @var \Enqueue\Sqs\SqsContext $psrContext */
$fooQueue = $psrContext->createQueue('foo');
$psrContext->purge($fooQueue);