GithubHelp home page GithubHelp logo

flavien-metivier / swarrotbundle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from swarrot/swarrotbundle

0.0 2.0 0.0 543 KB

A symfony2 bundle for swarrot integration

License: MIT License

PHP 75.32% HTML 24.68%

swarrotbundle's Introduction

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)

Running your tests without publishing

If you use Swarrot you may not want to realy publish messages like in test environment for example. You can use the BlackholePublisher to achieve this.

Simply override the swarrot.publisher.class parameter in the DIC with the Swarrot\SwarrotBundle\Broker\BlackholePublisher class.

Update config_test.yml for example:

parameters:
    swarrot.publisher.class: SP\Utils\Swarrot\BlackholePublisher

License

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

swarrotbundle's People

Contributors

adrienbrault avatar antoox avatar baldurrensch avatar blaugueux avatar jlepeltier avatar odolbeau avatar stof avatar thisisareku avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.