PHP Classes

AWS SQS Wrapper: Publish and subscribe message queues using AWS SQS

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 62 All time: 10,456 This week: 455Up
Version License PHP version Categories
aws-sqs-wrapper 1.0BSD License5PHP 5, Tools, Web services
Description 

Author

This package can publish and subscribe message queues using AWS SQS.

It provides simple means to publish and subscribe to message questions using Amazon Simple Queue System using a queue connection object that takes as parameter an object of the AWS SQS client.

Innovation Award
PHP Programming Innovation award nominee
November 2018
Number 9
Amazon Simple Queue System (AWS SQS) is a very popular format passing messages to queues of jobs to be processed by separate systems.

The AWS SQS SDK code is a bit complicated. This package provides a simpler solution around AWS SQS SDK that uses separate objects for connecting and queuing messages.

Manuel Lemos
Picture of Nguyen Duc Thuan
Name: Nguyen Duc Thuan <contact>
Classes: 3 packages by
Country: Viet Nam Viet Nam
Age: 37
All time rank: 252310 in Viet Nam Viet Nam
Week rank: 227 Up2 in Viet Nam Viet Nam Up
Innovation award
Innovation award
Nominee: 2x

Documentation

aws-sqs-wrapper

PHP library for simplified SQS queue messages processing.

Build Status

Introduction

  • This library converts send/receive/delete SQS messages results into objects. This enables you to utilize code autocompletion without memorizing common attribute names.
  • It removes your boilerplate code by introducing simplified send/receive/delete methods.
  • It decouples publishing and subscribing responsibilities so that your business logic is free from infrastructure awareness.

Installation

composer require ndthuan/aws-sqs-wrapper

Usage

Sending a message

use Aws\Sqs\SqsClient;
use Ndthuan\AwsSqsWrapper\Publishing\Publisher;
use Ndthuan\AwsSqsWrapper\Queue\Connector;

$queueUrl = ''; // get this from your own AWS SQS setup

// creating a publisher
$sqsClient = new SqsClient(...);
$queueConnector = new Connector($sqsClient, $queueUrl);
$publisher = new Publisher($queueConnector);

// send a string message
$publisher->publishString('My message body');
// or send a json serializable object/array
$myMessage = [
    'my' => 'data',
];
$publisher->publishJsonSerializable($myMessage);

Subscribing to a queue

use Aws\Sqs\SqsClient;
use Ndthuan\AwsSqsWrapper\Queue\Connector;
use Ndthuan\AwsSqsWrapper\Queue\ReceivedMessage;
use Ndthuan\AwsSqsWrapper\Queue\ResultMetadata;
use Ndthuan\AwsSqsWrapper\Subscribing\DelegatorSubscriber;

// defining a message processor
class MyMessageProcessor implements MessageProcessorInterface
{
    /
     * @inheritdoc
     */
    public function processMessage(ReceivedMessage $message, ResultMetadata $resultMetadata)
    {
        // your processing logic
    }
}

$queueUrl = ''; // get this from your own AWS SQS setup

// creating a subscriber
$sqsClient = new SqsClient(...);
$queueConnector = new Connector($sqsClient, $queueUrl);
$subscriber = new DelegatorSubscriber(new MyMessageProcessor(), $queueConnector);

// run the subscriber
$subscriber->pullAndProcessMessages();

Exception handling

A message processor may throw exceptions or errors. Subscriber will react differently depending on exception type:

  • On `LogicException` and `ValidationFailureException`: the corresponding message is deleted from queue and the subscriber continues to process other messages.
  • On `FatalException`: the corresponding message is not deleted from queue but the subscriber stops processing and bubbles up the exception.
  • On other kinds of `\Throwable`: the corresponding message is not deleted from queue and the subscriber continues to process other messages.

  Files folder image Files (35)  
File Role Description
Files folder imagesrc (3 directories)
Files folder imagetests (1 file, 2 directories)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file docker-compose.yml Data Auxiliary data
Accessible without login Plain text file install-xdebug.sh Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file run_tests.sh Data Auxiliary data
Accessible without login Plain text file run_tests_with_coverage.sh Data Auxiliary data
Accessible without login Plain text file wait_for.sh Data Auxiliary data

  Files folder image Files (35)  /  src  
File Role Description
Files folder imagePublishing (1 file)
Files folder imageQueue (6 files)
Files folder imageSubscribing (6 files, 2 directories)

  Files folder image Files (35)  /  src  /  Publishing  
File Role Description
  Plain text file Publisher.php Class Class source

  Files folder image Files (35)  /  src  /  Queue  
File Role Description
  Plain text file Connector.php Class Class source
  Plain text file MessageAttributes.php Class Class source
  Plain text file ReceivedMessage.php Class Class source
  Plain text file ReceiveMessageResult.php Class Class source
  Plain text file ResultMetadata.php Class Class source
  Plain text file SendMessageResult.php Class Class source

  Files folder image Files (35)  /  src  /  Subscribing  
File Role Description
Files folder imageCallbacks (3 files)
Files folder imageException (3 files)
  Plain text file AbstractSubscriber.php Class Class source
  Plain text file DelegatorSubscriber.php Class Class source
  Plain text file MessageProcessorInterface.php Class Class source
  Plain text file MessageValidatorInterface.php Class Class source
  Plain text file SubscriberInterface.php Class Class source
  Plain text file SubscribingException.php Class Class source

  Files folder image Files (35)  /  src  /  Subscribing  /  Callbacks  
File Role Description
  Plain text file LoggingCallbacks.php Class Class source
  Plain text file NullCallbacks.php Class Class source
  Plain text file SubscriberCallbacksInterface.php Class Class source

  Files folder image Files (35)  /  src  /  Subscribing  /  Exception  
File Role Description
  Plain text file FatalException.php Class Class source
  Plain text file LogicException.php Class Class source
  Plain text file ValidationFailureException.php Class Class source

  Files folder image Files (35)  /  tests  
File Role Description
Files folder imageintegration (1 file)
Files folder imageunit (3 directories)
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script

  Files folder image Files (35)  /  tests  /  integration  
File Role Description
  Plain text file ConnectorTest.php Class Class source

  Files folder image Files (35)  /  tests  /  unit  
File Role Description
Files folder imagePublishing (1 file)
Files folder imageQueue (1 file)
Files folder imageSubscribing (1 file, 1 directory)

  Files folder image Files (35)  /  tests  /  unit  /  Publishing  
File Role Description
  Plain text file PublisherTest.php Class Class source

  Files folder image Files (35)  /  tests  /  unit  /  Queue  
File Role Description
  Plain text file MessageAttributesTest.php Class Class source

  Files folder image Files (35)  /  tests  /  unit  /  Subscribing  
File Role Description
Files folder imageCallbacks (1 file)
  Plain text file DelegatorSubscriberTest.php Class Class source

  Files folder image Files (35)  /  tests  /  unit  /  Subscribing  /  Callbacks  
File Role Description
  Plain text file LoggingCallbacksTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:62
This week:0
All time:10,456
This week:455Up