PHPackages                             umer936/cakephp-rabbitmq - 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. umer936/cakephp-rabbitmq

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

umer936/cakephp-rabbitmq
========================

A RabbitMQ plugin for CakePHP 4

v4.0(3y ago)038MITPHPPHP &gt;=7.4

Since Jun 30Pushed 3y agoCompare

[ Source](https://github.com/umer936/cakephp-rabbitmq)[ Packagist](https://packagist.org/packages/umer936/cakephp-rabbitmq)[ Docs](https://github.com/umer936/cakephp-rabbitmq)[ RSS](/packages/umer936-cakephp-rabbitmq/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Working, but not maintained
===========================

[](#working-but-not-maintained)

---

I no longer use this plugin in favor of

Additionally, there is  which features a lot more transports, including AMQP Bunny (core of RabbitMQ):

See also:  for more options

This plugin will still live on in case someone needs RabbitMQ to just work in CakePHP 4

composer.json:

```
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/umer936/cakephp-rabbitmq.git"
        }
    ],

    "autoload": {
        "psr-4": {
            "DevApp\\RabbitMQ\\": "./vendor/umer936/cakephp-rabbitmq/src/"
        }
    },
```

```
composer require umer936/cakephp-rabbitmq

```

Application.php (likely don't need the options array but for some reason I added it at some point)

```
        $this->addPlugin('DevApp/RabbitMQ', [
            'bootstrap' => true,
            'path' => ROOT . DS . 'vendor' . DS . 'umer936' . DS . 'cakephp-rabbitmq' . DS,
        ]);
```

CakePHP RabbitMQ plugin
=======================

[](#cakephp-rabbitmq-plugin)

[![Build Status](https://camo.githubusercontent.com/d26b700e073f755d5e93d1a11da3514886367f82de03e84ba1cf210253fe57a8/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f303130304465762f63616b657068702d7261626269746d712f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/0100Dev/cakephp-rabbitmq)[![StyleCI Status](https://camo.githubusercontent.com/270567f302dfe4ac07da44c877a1a0a14c3c3994b14c4873bb9303eb6a74eea1/68747470733a2f2f7374796c6563692e696f2f7265706f732f34333734363735322f736869656c64)](https://styleci.io/repos/43746752)[![Coverage Status](https://camo.githubusercontent.com/5413dd5df62d7b484d7e04595c816162d355ebfe3393e083241c071c0f4bacf5/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f303130304465762f63616b657068702d7261626269746d712f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/0100Dev/cakephp-rabbitmq)[![Total Downloads](https://camo.githubusercontent.com/1db30f55c7e94683a85852243c732c5c5d3f5b21ebbfd86a3b91c03bb9e444e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f303130304465762f63616b657068702d7261626269746d712e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/0100Dev/cakephp-rabbitmq)[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)

RabbitMQ plugin for CakePHP 4.

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

[](#requirements)

- PHP 7.4+
- CakePHP 4.0+
- [RabbitMQ message broker](http://www.rabbitmq.com)

Why use this plugin?
--------------------

[](#why-use-this-plugin)

Use this plugin to drastically reduce page load times by offloading time consuming processes (like sending emails and resizing uploaded images) to a CLI consumer using messages in RabbitMQ. Could also be used to communicate with other systems or, for example, log lintes.

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

[](#installation)

Install the plugin using [Composer](https://getcomposer.org):

```
composer require 0100dev/cakephp-rabbitmq

```

Now load the plugin by either running this shell command:

```
bin/cake plugin load DevApp/RabbitMQ --bootstrap

```

or by manually adding the following line to `config/bootstrap.php`:

```
$this->addPlugin('DevApp/RabbitMQ', ['bootstrap' => true]);
```

Lastly, add a new `Gearman` configuration section to (most likely) `app.php`:

```
    'Gearman' => [
        'Servers' => [
            '127.0.0.1:4730'
        ],
        'Jobs' => [

        ]
    ]
```

### Optional: system verification

[](#optional-system-verification)

Before proceeding, you might want to verify that the [Gearman Job Server](http://gearman.org//getting-started) is actually up and running on your local system.

On Ubuntu systems running `sudo netstat -peanut | grep gearman` should produce something similar to:

```
tcp      0     0 127.0.0.1:4730     0.0.0.0:*     LISTEN     0     9727     625/gearmand
tcp6     0     0 ::1:4730           :::*          LISTEN     0     9726     625/gearmand

```

Usage
-----

[](#usage)

Using this plugin comes down to:

1. Configuring your task(s)
2. Starting the `WorkerShell` on your local system
3. Offloading tasks from within your application code by using the `execute()`function found in the `JobAwareTrait`

To start the `WorkerShell` so it will listen for incoming tasks run the following command on your local system:

```
bin/cake consumer

```

Built-in Tasks
--------------

[](#built-in-tasks)

### Email Task

[](#email-task)

This plugin comes with a built-in email task that allows you to start offloading emails using the worker instantly.

To enable the email task first add the following job to your Gearman configuration section:

```
    'Jobs' => [
        'className' => 'Email'
    ]
```

Then add the following worker configuration to your existing EmailTransporter configuration section (most likely found in `app.php`):

```
'worker' => [
    'className' => 'CvoTechnologies/Gearman.Worker',
    'transport' => 'default',
    'background' => true
]
```

Now all you need to do is use this EmailTransporter in your application when sending emails and it will automatically offload all email sending to the built-in task using the EmailTransporter defined in the `transport` key. E.g.

```
$email = new Email('default');
$res = $email->from(['you@example.com' => 'Your Site'])
    ->to('recipient@sexample.com')
    ->subject('Testing cakephp-gearman built-in EmailTask')
    ->send('Your message');
```

If things went well you should see the worker providing feedback on tasks being processed shown below:

[![Worker feedback](/docs/screenshot-worker-email.png)](/docs/screenshot-worker-email.png)

Creating your own tasks
-----------------------

[](#creating-your-own-tasks)

### 1. Create the Task

[](#1-create-the-task)

As an example we will create the following `SleepTask` that:

- will be used as a Gearman job
- must be created in `src/Shell/Task/SleepTask.php`
- must contain a `main()` function

```
