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;
$connectionFactory = new SqsConnectionFactory([
'key' => 'aKey',
'secret' => 'aSecret',
'region' => 'aRegion',
]);
$psrContext = $connectionFactory->createContext();
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);