gendoria/command-queue-rabbitmq-bundle

RabbitMQ driver bundle for Gendoria Command Queue

0.2.2 2016-10-24 13:55 UTC

This package is auto-updated.

Last update: 2024-10-27 04:54:01 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Downloads Latest Stable Version

RabbitMQ driver bundle for gendoria/command-queue-bundle.

Bundle created in cooperation with Isobar Poland.

Isobar Poland

Installation

Step 0: Prerequisites

⚠️ Before using this bundle, you should install and configure gendoria/command-queue-bundle and php-amqplib/rabbitmq-bundle.

For RabbitMQ Bundle you are required to configure only the 'connections' section. All required producers and consumers are created automatically by this bundle.

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require gendoria/command-queue-rabbitmq-bundle "~0.2.0"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Gendoria\CommandQueueRabbitMqDriverBundle\GendoriaCommandQueueRabbitMqDriverBundle(),
        );

        // ...
    }

    // ...
}

Gendoria Command Queue Bundle and php-amqplib/rabbitmq-bundle bundles should also be enabled and configured.

Step 3: Add bundle configuration

The example bundle configuration looks as one below.

gendoria_command_queue_rabbit_mq_driver:
    serializer: '@gendoria_command_queue.serializer.jms'
    drivers:
        poolname:
            rabbitmq_connection: default
            exchange_name: poolname-command-queue-bus
            consumer_name: poolname_command_queue_worker
            consumer_queue_name: poolname-command-queue-worker-consumer
            producer_name: poolname_command_queue

serializer parameter is used to specify serializer driver used by the driver. You should use jms or symfony driver here, where jms is preferred.

Some serializer drivers are provided by Gendoria Command Queue Bundle.

drivers key defines RabbitMQ command queue drivers. They can be then used by Gendoria Command Queue Bundle as pool drivers. For each Command Queue pool using RabbitMQ transport, one driver should be defined.

Driver configuration consists of several fields, describing connection and worker details. One driver entry has following keys:

  • rabbitmq_connection - Connection name, as definned in rabbitmq bundle configuration.
  • exchange_name - Exchange name for RabbitMQ.
  • consumer_name - consumer name for RabbitMQ bundle.
  • consumer_queue_name - Queue name for RabbitMQ.
  • producer_name - Producer name for RabbitMQ bundle.

This bundle appends appropriate consumers and producers to php-amqplib/rabbitmq-bundle, so no additional consumer / producer configuration is needed.

For each defined driver, service gendoria_command_queue_rabbit_mq_driver.driver.driverName will be created, where driverName is the key in drivers configuration. So for above configuration, one service with ID gendoria_command_queue_rabbit_mq_driver.driver.poolname will be present.

Step 4: Add a driver to Command Queue Bundle configuration

For each command queue pool you want to use rabbitmq driver on, you should set it as send_driver.

So for gendoria_command_queue_rabbit_mq_driver.driver.poolname, your configuration should look similar to code below.

gendoria_command_queue:
    ...
    pools:
        ...
        poolname:
            send_driver: '@gendoria_command_queue_rabbit_mq_driver.driver.poolname'

Step 5: Setup RabbitMQ fabric

This step is done by php-amqplib/rabbitmq-bundle command.

$ app/console rabbitmq:setup-fabric

It is optional, if you start your consumers before starting sending commands to queue.

Usage

To start receiving commands for your pool, you have to start one rabbitmq bundle worker process.

The command to do that is:

$ app/console cmq:worker:run rmq.poolname

Where poolname is the pool name you defined in pools section of configuration.

For the configuration from step 3, it will look like that:

$ app/console cmq:worker:run poolname

You should use services like supervisord to control running and restarting your workers.