alvarium / carrot-cake
RabbitMQ plugin for CakePHP
Installs: 1 093
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:cakephp-plugin
Requires
- cakephp/cakephp: ^3.5
- php-amqplib/php-amqplib: ^2.8
Requires (Dev)
- phpunit/phpunit: ^5.7.14|^6.0
This package is auto-updated.
Last update: 2024-10-26 00:01:28 UTC
README
Carrot Cake is a CakePHP plugin for publishing and subscribing to RabbitMQ queues/exchanges.
BTW we like to pronounce it like in japanese: Kyarottokēki (キャロットケーキ), that's why we wrote it that way in the title 😄.
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require alvarium/carrot-cake
Usage
Configuring
You can create a defaults settings file by adding a rabbit.php
file under your config file. The plugin will take that settings as defaults but you'll be able to overwrite them later on each loaded component.
The contents of such file can be with any of the following settings:
<?php return [ 'rabbit' => [ 'server' => [ 'host' => 'rabbit', 'port' => 5672, 'user' => 'guest', 'password' => 'guest', 'vhost' => '/', 'type' => 'direct', ], 'behavior' => [ // Check out the behavior section for details about its settings ], 'component' => [ // Check out the component section for details about its settings ], ], ];
Publisher Behavior
First you'll need to load the behavior in the desired table, when doing so you can override any of the previously defined settings + some specific settings for the behavior, like the used exchange (by default is tablename
):
<?php namespace App\Model\Table; use Cake\ORM\Table; class ArticlesTable extends Table { public function initialize(array $config) { parent::initialize($config); $this->addBehaviors([ 'Alvarium/CarrotCake.Publisher' => [ 'vhost' => '/custom-vhost', 'exchange' => 'custom_exchange_name', ], ]) } }
By default the behavior will send payloads to exchange.route
, where route can be any of:
- created
- updated
- deleted
Of course you can change these too by setting a routes
key and set your desired names for each route:
$this->addBehaviors([ 'Alvarium/CarrotCake.Publisher' => [ 'routes' => [ 'create' => 'published', 'update' => 'changed', 'delete' => 'unpublished', ], ], ])
Checklist
- Publisher
- Behavior
- Component
- Consumer
- Component
License
Copyright Alvarium.io (c) 2019