Code Monkey home page Code Monkey logo

command-bus-bundle's Introduction

RezzzaCommandBusBundle

Integration of the CommandBus library into Symfony2.

Installation

Require rezzza/command-bus-bundle to your composer.json file:

{
    "require": {
        "rezzza/command-bus-bundle": "~2.0"
    }
}

Register the bundle in app/AppKernel.php:

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Rezzza\CommandBusBundle\RezzzaCommandBusBundle()
    );
}

Update your config.yml:

framework:
    serializer:
        enabled: true

Usage

$bus = $container->get('rezzza_command_bus.command_bus.synchronous'); // synchronous is the name you given to your bus in configuration.
$bus->handle(new FooCommand());

Bus

Direct, SncRedis & OldSoundRabbit are currently supported.

Commands

Commands must inherit from Rezzza\CommandBus\Domain\CommandInterface.

Register a command handler:

<service id="...." class="....">
    <tag name="rezzza_command_bus.command_handler" command="FQCN\MyFirstActionCommand" /> <!-- when handle this command, method `myFirstAction` will be handled. -->
    <tag name="rezzza_command_bus.command_handler" command="FQCN\MySecondActionCommand" method="myMethod" />
</service>

Events

Events:

- on_consumer_response
- pre_handle_command

Register a listener:

<service id="service_id" class="Foo">
    <tag name="rezzza_command_bus.event_listener" event="pre_handle_command" method="onPreHandleCommand" />
    <tag name="rezzza_command_bus.event_listener" event="on_consumer_response" method="onConsumerResponse" />
</service>

Fail Strategy

See command-bus documentation.

Console Command

A Symfony console command is provided in this bundle

$ app/console rezzza:command_bus:consume "CommandToConsume"

Options available:

 --consumer             Which consumer should we use ? (default: "default")
 --iteration-limit (-i) Limit of iterations, -1 for infinite.. (default: -1)
 --time-limit           During how many time this command will listen to the queue. (default: 60)
 --usleep               Micro seconds (default: 100000)
 --lock                 Only one command processing ?

To watch activity of your consumer, you should register a console handler for monolog

monolog:
    handlers:
        console:
            type:   console
            verbosity_levels:
                VERBOSITY_NORMAL: NOTICE

Configuration

rezzza_command_bus:
    buses:
      synchronous: direct
      asynchronous:
        rabbitmq:
          #define producer_guesser which allow to determine rigth producer for each command
          #producer name and command class name must be indentical
            #example:
            #producer name : source_entry_update
            #command class name : SourceEntryUpdateCommand
          producer_guesser: rezzza_command_bus.old_sound_rabbit.producer_guesser
          consumer_bus: synchronous #consumer handle command with synchronous bus
        snc_redis:
            client: default # snc redis client.
            read_block_timeout: 1 # see blpop documentation
            consumers:
                default:
                    bus: synchronous
                    fail_strategy:
                        retry_then_fail: # When the command fail, it uses this strategy.
                        # you could use too requeue, none, service.
                            attempts: 10
                            requeue_on_fail: true
    handlers: # Do you want to use handlers provided in this bundle ?
        retry:  synchronous  # If you used retry_then_fail strategy, this handler is linked to Retry commands.
        failed: synchronous # If you used retry_then_fail strategy, this handler is linked to Failed commands.

Usage with JMS Serializer

rezzza_command_bus:
    logger_normalizer: symfony_serializer

services:
    symfony_serializer:
        class: "Symfony\Component\Serializer\Serializer"

command-bus-bundle's People

Contributors

azoog avatar fberthereau avatar hadeli avatar mtrudu avatar scullwm avatar shouze avatar stephpy avatar tyx 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.