The RabbitMqSqlBundle is a symfony worker to provide rabbitmq message persistence for your application using the php-amqplib/rabbitmq-bundle and doctrine/dbal libraries.
You just need to configure the mapping in yml and execute a command, a simple and scalable rabbitmq to sql consumer to persist your entities:
php app/console rabbitmq:consumer -w sql
- mapping yml config (doctrine like)
- Insert records
- Update records
- Relational records : oneToOne, oneToMany, manyToOne, manyToMany
- Update, Delete relations
- Foreign keys support
Following example shows you the consuming process to persist in database a simple subscriber from an asynchronous message data.
RabbitMQ incoming message data:
{
"name" : "Rogger Rabbit",
"email" : "[email protected]",
"Groups": [ { "slug": "subscriber" } ]
}
SQL requests output:
INSERT INTO `members` (`name`, `email`) VALUES ("Rogger Rabbit", "[email protected]");
INSERT INTO `member_group` (`member_id`, `group_id`) VALUES (3, 2);
Take more inspiration from Examples documentation
This application is under the MIT license. See the complete license in this file :
Resources/meta/LICENSE
Require the worker and its dependencies with composer:
$ composer require florianajir/rabbitmq-sql-worker
Register this bundles:
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
new OldSound\RabbitMqBundle\OldSoundRabbitMqBundle(),
new FlorianAjir\RabbitMqSqlBundle\FlorianAjirRabbitMqSqlBundle(),
);
}
You have to configure the rabbitmq and the database and define message structures and database mapping.
Enjoy !