Developed with love by KnpLabs Hire us for your project!
43

SwarrotBundle

by swarrot

A symfony2 bundle for swarrot integration

SwarrotBundle

Build Status
Scrutinizer Code Quality
SensioLabsInsight
Latest Stable Version
Latest Unstable Version

A bundle to use swarrot inside your Symfony2 application

Installation

The recommended way to install this bundle is through
Composer. Require the swarrot/swarrot-bundle
package into your composer.json file:

{
    "require": {
        "swarrot/swarrot-bundle": "@stable"
    }
}

Protip: you should browse the
swarrot/swarrot-bundle
page to choose a stable version to use, avoid the @stable meta constraint.

Update app/AppKernel.php:

public function registerBundles()
{
    $bundles = array(
        // ...
        new Swarrot\SwarrotBundle\SwarrotBundle(),
    );

    return $bundles;
}

Configuration reference

swarrot:
    provider: pecl # pecl or amqp_lib
    default_connection: rabbitmq
    default_command: swarrot.command.base # Swarrot\SwarrotBundle\Command\SwarrotCommand
    connections:
        rabbitmq:
            host: "%rabbitmq_host%"
            port: "%rabbitmq_port%"
            login: "%rabbitmq_login%"
            password: "%rabbitmq_password%"
            vhost: '/'
    processors_stack:
        signal_handler: 'Swarrot\Processor\SignalHandler\SignalHandlerProcessor'
        ack: 'Swarrot\Processor\Ack\AckProcessor'
        max_messages: 'Swarrot\Processor\MaxMessages\MaxMessagesProcessor'
        retry: 'Swarrot\Processor\Retry\RetryProcessor'
        exception_catcher: 'Swarrot\Processor\ExceptionCatcher\ExceptionCatcherProcessor'
        max_execution_time: 'Swarrot\Processor\MaxExecutionTime\MaxExecutionTimeProcessor'
    consumers:
        my_consumer:
            processor: my_consumer.processor.service
            extras:
                retry_exchange: my_consumer_exchange
                retry_attempts: 3
                retry_routing_key_pattern: 'retry_%%attempt%%'
    messages_types:
        my_publisher:
            connection: rabbitmq # use the default connection by default
            exchange: my_exchange
            routing_key: my_routing_key

Publish a message

First step is to retrieve the swarrot publisher service from your controller.

$messagePublisher = $this->get('swarrot.publisher');

After you need to prepare your message with the
Message
class.

use Swarrot\Broker\Message;

$message = new Message('"My first message with the awesome Swarrot lib :)"');

Then you can publish a new message into a predefined configuration (connection,
exchange, routing_key, etc.) from your message_types.

$messagePublisher->publish('webhook.send', $message);

When publishing a message you can override the message_types configuration by
passing a third argument:

$messagePublisher->publish('webhook.send', $message, array(
    'exchange'    => 'my_new_echange',
    'connection'  => 'my_second_connection',
    'routing_key' => 'my_new_routing_key'
));

Consume a message

Swarrot will automatically create new commands according to your configuration.
This command need the queue name to consume as first argument. You can also use
a named connection as second argument if you don't want to use the default one.

app/console swarrot:consume:my_consumer_name queue_name [connection_name]

Your processor will automatically be decorated by all processors named in the
processors_stack section. No matter the order you list your processors,
here is the default order:

  • SignalHandler
  • ExceptionCatcher
  • MaxMessages
  • MaxExecutionTime
  • Ack
  • Retry

All this processors are configurable with some options:

  • --poll-interval [default: 500000]: Change the polling interval when no message found in broker
  • --requeue-on-error (-r): Re-queue the message in the same queue if an error occurred.
  • --no-catch (-C): Disable the ExceptionCatcher processor (available only if the processor is in the stack)
  • --max-execution-time (-t) [default: 300]: Configure the MaxExecutionTime processor (available only if the processor is in the stack)
  • --max-messages (-m) [default: 300]: Configure the MaxMessages processor (available only if the processor is in the stack)
  • --no-retry (-R): Disable the Retry processor (available only if the processor is in the stack)

License

This bundle is released under the MIT License. See the bundled LICENSE file for
details.

Copyright (c) 2014 Swarrot

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
  • Merge pull request #42 from gignonje/object-manager-processor
    By odolbeau, 2 years ago
  • Added Doctrine ObjectManagerProcessor support
    By , 2 years ago
  • Merge pull request #40 from stof/patch-2
    By Olivier Dolbeau, 2 years ago
  • Improved the travis configuration
    By stof, 2 years ago
  • Require php 5.4
    By odolbeau, 2 years ago
  • Merge pull request #38 from adrienbrault/fix-default-queue
    By Olivier Dolbeau, 2 years ago
  • Fix command default queue issue
    By adrienbrault, 2 years ago
  • Merge pull request #36 from adrienbrault/patch-1
    By Olivier Dolbeau, 2 years ago
  • Fix readme example syntax
    By adrienbrault, 2 years ago
  • Merge pull request #35 from baldurrensch/patch-1
    By Olivier Dolbeau, 2 years ago
  • Update README.md
    By baldurrensch, 2 years ago
  • Merge pull request #34 from adrienbrault/consumer-default-queue
    By Olivier Dolbeau, 2 years ago
  • Add ability to configure consumer default queue
    By adrienbrault, 2 years ago
  • Merge pull request #31 from antoox/hotfix-retry-attempts
    By Olivier Dolbeau, 3 years ago
  • Do not check whether the retry-attempts option exists.
    By , 3 years ago
  • Fix the retry attempts number when no option is defined.
    By antoox, 3 years ago
  • Merge pull request #29 from odolbeau/prepare-new-verison
    By Olivier Dolbeau, 3 years ago
  • Prepare new version
    By odolbeau, 3 years ago
  • Merge pull request #28 from antoox/add-retry-attempts-option
    By Olivier Dolbeau, 3 years ago
  • Add a retry-attempts option.
    By antoox, 3 years ago
  • Merge pull request #26 from stof/fix_config
    By Olivier Dolbeau, 3 years ago
  • Fixed the DI configuration
    By stof, 3 years ago
  • Merge pull request #24 from ThisIsAreku/amqplib
    By Olivier Dolbeau, 3 years ago
  • Moved php-amqplib to suggest
    By , 3 years ago
  • Allow any registered provider
    By ThisIsAreku, 3 years ago
  • Added php-amqplib support
    By ThisIsAreku, 3 years ago
  • Merge pull request #22 from blaugueux/patch-2
    By Olivier Dolbeau, 3 years ago
  • Improved exception message.
    By blaugueux, 3 years ago
  • Merge pull request #19 from odolbeau/feat-correct-processor-order
    By Olivier Dolbeau, 3 years ago
  • Merge pull request #21 from odolbeau/add-new-options
    By Olivier Dolbeau, 3 years ago