Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ndthuan/aws-sqs-wrapper
PHP library for simplified SQS queue messages processing
https://github.com/ndthuan/aws-sqs-wrapper
aws aws-sqs-wrapper php php-library php7 php70 php71 php72 php73 sqs sqs-client sqs-consumer sqs-interface sqs-message sqs-poller sqs-queue sqs-queues
Last synced: about 3 hours ago
JSON representation
PHP library for simplified SQS queue messages processing
- Host: GitHub
- URL: https://github.com/ndthuan/aws-sqs-wrapper
- Owner: ndthuan
- License: mit
- Created: 2018-11-10T05:26:02.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-26T12:39:49.000Z (almost 6 years ago)
- Last Synced: 2024-01-28T11:19:28.427Z (8 months ago)
- Topics: aws, aws-sqs-wrapper, php, php-library, php7, php70, php71, php72, php73, sqs, sqs-client, sqs-consumer, sqs-interface, sqs-message, sqs-poller, sqs-queue, sqs-queues
- Language: PHP
- Homepage:
- Size: 486 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aws-sqs-wrapper
PHP library for simplified SQS queue messages processing.![Build Status](https://travis-ci.org/ndthuan/aws-sqs-wrapper.svg?branch=master)
## 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
```bash
composer require ndthuan/aws-sqs-wrapper
```## Usage
### Sending a message
```php
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
```php
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.