Skip to content

Latest commit

 

History

History
106 lines (73 loc) · 2.11 KB

sqs.md

File metadata and controls

106 lines (73 loc) · 2.11 KB

Amazon SQS transport

A transport for Amazon SQS broker. It uses internally official aws sdk library

Installation

$ composer require enqueue/sqs

Create context

<?php
use Enqueue\Sqs\SqsConnectionFactory;

$connectionFactory = new SqsConnectionFactory([
    'key' => 'aKey',
    'secret' => 'aSecret',
    'region' => 'aRegion',
]);

$psrContext = $connectionFactory->createContext();

Declare queue.

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);

Send message to queue

<?php
/** @var \Enqueue\Sqs\SqsContext $psrContext */

$fooQueue = $psrContext->createQueue('foo');
$message = $psrContext->createMessage('Hello world!');

$psrContext->createProducer()->send($fooQueue, $message);

Send delay 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)
;

Consume 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);

Purge queue messages:

<?php
/** @var \Enqueue\Sqs\SqsContext $psrContext */

$fooQueue = $psrContext->createQueue('foo');

$psrContext->purge($fooQueue);

back to index