<commit_before># RabbitMqBundle #

## About ##

The RabbitMqBundle incorporates messaging in your application via [RabbitMq](http://www.rabbitmq.com/) using the [php-amqplib](http://github.com/videlalvaro/php-amqplib) library.

The bundle implements several messaging patterns as seen on the [Thumper](https://github.com/videlalvaro/Thumper) library. Therefore publishing messages to RabbitMQ from a Symfony2 controller is as easy as:

    $msg = array('user_id' => 1235, 'image_path' => '/path/to/new/pic.png');
    $this->get('old_sound_rabbit_mq.upload_picture_producer')->publish(serialize($msg));

Later when you want to consume 50 messages out of the `upload_pictures` queue, you just run on the CLI:

    $ ./app/console rabbitmq:consumer -m 50 upload_picture

All the examples expect a running RabbitMQ server.

This Bundle was presented at [Symfony Live Paris 2011](http://www.symfony-live.com/paris/schedule#session-av1) conference. See the slides [here](http://www.slideshare.net/old_sound/theres-a-rabbit-on-my-symfony):

## Installation ##

The following instructions have been tested on a project created with the [Symfony2 Standard 2.0.6](http://symfony.com/download?v=Symfony_Standard_2.0.6.tgz)

Put the RabbitMqBundle and the [php-amqplib](http://github.com/videlalvaro/php-amqplib) library into the deps file:

    ...
    [RabbitMqBundle]
    git=http://github.com/videlalvaro/RabbitMqBundle.git
    target=/bundles/OldSound/RabbitMqBundle

    [php-amqplib]
    git=http://github.com/videlalvaro/php-amqplib.git
    target=videlalvaro/php-amqplib
    ...

Register the bundle and library namespaces in the `app/autoload.php` file:

    $loader->registerNamespaces(array(
        ...
        'OldSound'         => __DIR__.'/../vendor/bundles',
        'PhpAmqpLib'       => __DIR__.'/../vendor/videlalvaro/php-amqplib',
        ...
    ));

Add the RabbitMqBundle to your application's kernel:

    public function registerBundles()
    {
        $bundles = array(
            ...
            new OldSound\RabbitMqBundle\OldSoundRabbitMqBundle(),
            ...
        );
        ...
    }

### Warning - BC Breaking Changes ###

* Since 2012-04-24 The ConsumerInterface::execute method signature has changed
* Since 2012-01-03 the consumers execute method gets the whole AMQP message object and not just the body. See the CHANGELOG file for more details.

## Usage ##

Configure the `rabbitmq` service in your config:

    old_sound_rabbit_mq:
        connections:
            default:
                host:      'localhost'
                port:      5672
                user:      'guest'
                password:  '<PASSWORD>'
                vhost:     '/'
        producers:
            upload_picture:
                connection: default
                exchange_options: {name: 'upload-picture', type: direct}
        consumers:
            upload_picture:
                connection: default
                exchange_options: {name: 'upload-picture', type: direct}
                queue_options:    {name: 'upload-picture'}
                callback:         upload_picture_service
        ...

Here we configure the connection service and the message endpoints that our application will have. In this example your service container will contain the service `rabbitmq.upload_picture_producer` and `rabbitmq.upload_picture_consumer`. The later expects that there's a service called `upload_picture_service`.

If you don't specify a connection for the client, the client will look for a connection with the same alias. So for our `upload_picture` the service container will look for an `upload_picture` connection.

## Producers, Consumers, What? ##

In a messaging application, the process sending messages to the broker is called __producer__ while the process receiving those messages is called __consumer__. In your application you will have several of them that you can list under their respective entries in the configuration.

### Producer ###

A producer will be used to send messages to the server. In the AMQP Model, messages are sent to an __exchange__, this means that in the configuration for a producer you will have to specify the connection options along with the exchange options, which usually will be the name of the exchange and the type of it.<commit_msg>updates documentation for HA queues<commit_after># RabbitMqBundle #

## About ##

The RabbitMqBundle incorporates messaging in your application via [RabbitMq](http://www.rabbitmq.com/) using the [php-amqplib](http://github.com/videlalvaro/php-amqplib) library.

The bundle implements several messaging patterns as seen on the [Thumper](https://github.com/videlalvaro/Thumper) library. Therefore publishing messages to RabbitMQ from a Symfony2 controller is as easy as:

    $msg = array('user_id' => 1235, 'image_path' => '/path/to/new/pic.png');
    $this->get('old_sound_rabbit_mq.upload_picture_producer')->publish(serialize($msg));

Later when you want to consume 50 messages out of the `upload_pictures` queue, you just run on the CLI:

    $ ./app/console rabbitmq:consumer -m 50 upload_picture

All the examples expect a running RabbitMQ server.

This Bundle was presented at [Symfony Live Paris 2011](http://www.symfony-live.com/paris/schedule#session-av1) conference. See the slides [here](http://www.slideshare.net/old_sound/theres-a-rabbit-on-my-symfony):

## Installation ##

The following instructions have been tested on a project created with the [Symfony2 Standard 2.0.6](http://symfony.com/download?v=Symfony_Standard_2.0.6.tgz)

Put the RabbitMqBundle and the [php-amqplib](http://github.com/videlalvaro/php-amqplib) library into the deps file:

    ...
    [RabbitMqBundle]
    git=http://github.com/videlalvaro/RabbitMqBundle.git
    target=/bundles/OldSound/RabbitMqBundle

    [php-amqplib]
    git=http://github.com/videlalvaro/php-amqplib.git
    target=videlalvaro/php-amqplib
    ...

Register the bundle and library namespaces in the `app/autoload.php` file:

    $loader->registerNamespaces(array(
        ...
        'OldSound'         => __DIR__.'/../vendor/bundles',
        'PhpAmqpLib'       => __DIR__.'/../vendor/videlalvaro/php-amqplib',
        ...
    ));

Add the RabbitMqBundle to your application's kernel:

    public function registerBundles()
    {
        $bundles = array(
            ...
            new OldSound\RabbitMqBundle\OldSoundRabbitMqBundle(),
            ...
        );
        ...
    }

### Warning - BC Breaking Changes ###

* Since 2012-04-24 The ConsumerInterface::execute method signature has changed
* Since 2012-01-03 the consumers execute method gets the whole AMQP message object and not just the body. See the CHANGELOG file for more details.

## Usage ##

Configure the `rabbitmq` service in your config:

    old_sound_rabbit_mq:
        connections:
            default:
                host:      'localhost'
                port:      5672
                user:      'guest'
                password:  '<PASSWORD>'
                vhost:     '/'
        producers:
            upload_picture:
                connection: default
                exchange_options: {name: 'upload-picture', type: direct}
        consumers:
            upload_picture:
                connection: default
                exchange_options: {name: 'upload-picture', type: direct}
                queue_options:    {name: 'upload-picture'}
                callback:         upload_picture_service
        ...

Here we configure the connection service and the message endpoints that our application will have. In this example your service container will contain the service `rabbitmq.upload_picture_producer` and `rabbitmq.upload_picture_consumer`. The later expects that there's a service called `upload_picture_service`.

If you don't specify a connection for the client, the client will look for a connection with the same alias. So for our `upload_picture` the service container will look for an `upload_picture` connection.

If you need to use HA Queues then your queue options can be something like this:

    queue_options:    {name: 'upload-picture', arguments: {'x-ha-policy': ['S', 'all']}}

Adapt the `arguments` according to your needs.

## Producers, Consumers, What? ##

In a messaging application, the process sending messages to the broker is called __producer__ while the process receiving those messages is called __consumer__. In your application you will have several of them that you can list under their respective entries in the configuration.

### Producer ###

A producer will be used to send messages to the server. In the AMQP Model, messages are sent to an __exchange__, this means that in the configuration for a producer you will have to specify the connection options along with the exchange options, which usually will be the name of the exchange and the type of it.
{'fraction_non_alphanumeric': 0.08956403885249604, 'fraction_numerical': 0.009261350801897448, 'mean_word_length': 3.0378476972184223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7402478', 'n_tokens_mistral': 2585, 'n_tokens_neox': 2409, 'n_words': 849}