geekcom/felicio

A simple lib to connect PHP with AWS SQS

2.5.2 2020-09-09 15:03 UTC

README

A simple AWS SQS Messages with PHP

Scrutinizer Code Quality Latest Stable Version Minimum PHP Version License

About Felicio and SQS

Felicio is a simple library to manipulate AWS SQS Messages.

  • Simple;
  • Configurable;
  • Testable;
  • Open source.

Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications.

Installation

Install Composer if you don't have it.

composer require geekcom/felicio

Or in your file'composer.json' add:

{
    "require": {
        "geekcom/felicio": "^2.5.0"
    }
}

And the just run:

composer install

and thats it.

Configure

Rename .felicio.example to .felicio and fill in the correct information about your AWS SQS account.

AWS_SQS_ACCESS_KEY=
AWS_SQS_SECRET_KEY=
AWS_SQS_REGION=
AWS_SQS_API_VERSION=latest

Send a message

require __DIR__ . '/vendor/autoload.php';

use Felicio\Felicio;

$felicioDotFile = __DIR__ . '/.felicio';

$felicio = new Felicio($felicioDotFile);

$params = [
    'QueueUrl' => 'https://sqs.us-west-2.amazonaws.com/999999999/my_queue',
    'MessageBody' => 'test message'
];

$felicio->sendMessage($params);

Receive a message

require __DIR__ . '/vendor/autoload.php';

use Felicio\Felicio;

$felicioDotFile = __DIR__ . '/.felicio';

$felicio = new Felicio($felicioDotFile);

$params = [
    'AttributeNames' => ['SentTimestamp'],
    'MaxNumberOfMessages' => 1,
    'MessageAttributeNames' => ['All'],
    'QueueUrl' => 'https://sqs.us-west-2.amazonaws.com/999999999/my_queue',
    'WaitTimeSeconds' => 0,
];

$message = $felicio->receiveMessage($params);

var_dump($message);

Delete a message

require __DIR__ . '/vendor/autoload.php';

use Felicio\Felicio;

$felicioDotFile = __DIR__ . '/.felicio';

$felicio = new Felicio($felicioDotFile);

$params = [
    'QueueUrl' => 'https://sqs.us-west-2.amazonaws.com/999999999/my_queue',
    'ReceiptHandle' => '', // required
];

$felicio->deleteMessage($params);

Count messages

require __DIR__ . '/vendor/autoload.php';

use Felicio\Felicio;

$felicioDotFile = __DIR__ . '/.felicio';

$felicio = new Felicio($felicioDotFile);

$queueUrl = 'https://sqs.us-west-2.amazonaws.com/999999999/my_queue';

$messages = $felicio->countMessages($queueUrl);

var_dump($messages);

Contributing

Feel free to contribute, make a fork!

License

The Felicio library is open-source software licensed under the MIT license.

Questions?

Open a new Issue or look for a closed issue

Author