PHPackages                             lorenzo/cakephp-sqs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. lorenzo/cakephp-sqs

ActiveCakephp-plugin[Queues &amp; Workers](/categories/queues)

lorenzo/cakephp-sqs
===================

CakePHP Aws Simple Queue System

2.1.1(8y ago)19302.4k↑58.3%14[2 PRs](https://github.com/lorenzo/cakephp-sqs/pulls)MITPHP

Since Jul 6Pushed 3y ago6 watchersCompare

[ Source](https://github.com/lorenzo/cakephp-sqs)[ Packagist](https://packagist.org/packages/lorenzo/cakephp-sqs)[ Docs](https://github.com/lorenzo/cakephp-sqs)[ RSS](/packages/lorenzo-cakephp-sqs/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (5)Dependencies (5)Versions (7)Used By (0)

AWS Simple Queue Service for CakePHP 3
======================================

[](#aws-simple-queue-service-for-cakephp-3)

[![Build Status](https://camo.githubusercontent.com/e3f3d675b0bb36d8dff702e069a8e1b49bb723763d2486ebb141f5251a269ad8/68747470733a2f2f7472617669732d63692e6f72672f6c6f72656e7a6f2f63616b657068702d7371732e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/lorenzo/cakephp-sqs)

This plugin is an adaptor for the original AWS SDK classes related to the Simple Queue Service (SQS). What in offers is an utility class that will handle construction and configuration of the HTTP client based on the information stored in the Configure class.

Additionally, it provides a Task class that will help you build long lived worker processes in no time.

Requirements
------------

[](#requirements)

- CakePHP 3.4.x
- PHP 5.6+

Installation
------------

[](#installation)

The only installation method supported by this plugin is by using composer. Just add this to your composer.json configuration:

```
composer require lorenzo/cakephp-sqs

```

### Enable plugin

[](#enable-plugin)

You need to enable the plugin your `config/bootstrap.php` file:

```
Plugin::load('CakeSQS');

```

### Configuration

[](#configuration)

The plugin expects the following configuration data in the Configure keys:

```
Configure::write('CakeSQS', [
    'connection' => [
        /**
         * @see http://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.Sqs.SqsClient.html#___construct
         * for all possible config params
         */
        'credentials' => [
            'key' => 'Your amazon key',
            'secret' => 'Your amazon secret',
        ],
        'version' => '2012-11-05', // you don't need to change this
        'region' => 'eu-central-1' // must match the region where the sqs queue was created
    ],
    'queues' => [
        'testQueue1' => 'sqs queue url, for example: https://sqs.eu-central-1.amazonaws.com/12345/someQueue'
    ]
]);

```

Or you can configure the connector class via `setConfig`

```
$this->SimpleQueue = new SimpleQueue();
$this->SimpleQueue->setConfig([
    'connection.credentials' => [
        'key' => 'SOMEKEY',
        'secret' => 'SOMESECRET',
    ],
    'queues.testQueue1' => 'sqs queue url, for example: https://sqs.eu-central-1.amazonaws.com/12345/someQueue'
]);

```

Storing a message in the Queue
------------------------------

[](#storing-a-message-in-the-queue)

```
$this->SimpleQueue->send('testQueue1', [
    'key1' => 'value1',
    'key2' => 'value2',
]);

```

The return value is an \\Aws\\Result object

Storing multiple messages as a batch
------------------------------------

[](#storing-multiple-messages-as-a-batch)

```
$this->SimpleQueue->send('testQueue1', [
    'key1' => 'value1',
    'key2' => 'value2',
]);

```

The return value of this method is an array with all messages that could not be stored (if any), having the same numeric position in the array as the one you sent. For example if the second and forth messages in your array failed, then the array will contain:

```
[1 => 'Error Message', 3 => 'Another error message']

```

Receiving a message from a queue
--------------------------------

[](#receiving-a-message-from-a-queue)

```
$msgResult = $this->SimpleQueue->receiveMessage('testQueue1');

```

The return value is unaltered from the AWS SDK. Please refer to its documentation for more info. For example:

```
$msgResult = $this->SimpleQueue->receiveMessage('testQueue1');
$msgResult->search('Messages');
// would return
[
    [
        'MessageId' => '929a9cfe-0d45-494c-80fc-41ec6e2e017d',
        'ReceiptHandle' => 'AQEBEYj8zzBaKn8PpJiHgvyznyo7H0BQYH7MBy7429K/ad53lXLRh5yu2Yb0EH9o22WskOCTX7enwcGxTc7JQLQPcJwFwJB/L29pVOyDvZc8fI2XPjd+7jbN91H6PqfHUUsryiDHkA36ZH0tWKjFOVt986GKptqdON+BbinT2KIjd5NLwN2sr7kWgWKhva6YSC/BIWTsSUyAfiFGRDLksNtMiXJk2nFzwvINGU7khBdDpZ0xZxmhhPvT3TPQeSukZNEp859yZLVA9t69Vx2Rrtf/3vGfZj9NjSVrEMcquP8zDrmIicp5+ILtm1qYJxq2lsYH0LHTwGtIQC1nW+J7D/t3JAFZdgohsdXEl3T+KIig2APUgJz4Mp/ze3gzIrY7/Y+plII+MnrISdBSmDnoRRpF/g==',
        'MD5OfBody' => 'ff45cc3835165307ef414c23ca2c6f67',
        'Body' => '{"key1":"value1","key2":"value2"}'
    ]
];

```

Deleting a message from a queue
-------------------------------

[](#deleting-a-message-from-a-queue)

```
$msgResult = $this->SimpleQueue->receiveMessage('testQueue1');
$handle = $msgResult['Messages'][0]['ReceiptHandle'];
$this->SimpleQueue->deleteMessage('testQueue1', $handle);

```

Setting up a worker shell
-------------------------

[](#setting-up-a-worker-shell)

As mentioned before, this plugin helps you create long lived worker shells that will process jobs one at a time as messages are received from a set of queues in CakeSQS. This is an example

```
