GithubHelp home page GithubHelp logo

danielsan80 / async-task Goto Github PK

View Code? Open in Web Editor NEW

This project forked from toretto460/async-task

0.0 3.0 0.0 170 KB

Symfony2 Bundle builded on top of RabbitMq that allows to process asynchronously messages

symfony sf2 bundle old

async-task's Introduction

AsyncTasksBundle

About

The AsyncTasksBundle allows to send asynchronous messages in your Symfony2 Application via RabbitMq (using the php-amqplib library).

PUBLISHING

The message publishing is so easy.

  • Create an async event Trt\AsyncTasksBundle\Event\AsyncEvent
  • Dispatch it!
  • Done
    $event = new AsyncEvent(
        'async_event_name',
        array('date'=> (new \DateTime())->format('d-m-Y H:s')
        )
    );
    $this->get('event_dispatcher')->dispatch($event->getName(), $event);

CONSUMING

Now if you want consume the messages

  • Write your domain specific service implementing the Trt\AsyncTasksBundle\Listener\ListenerInterface interface.
  • Tag the service with {name: trt_async.listener.listen, event: async_event_name} , the event key is the event name.
  • Run
$ app/console trt:async:run async_event_name

All the examples expect a running RabbitMQ server.

Installation

This instructions have been tested on a project created with the Symfony2 Standard 2.3.4

Add the AsyncTasksBundle to your composer.json and type composer install.

    "require": {
        "php": ">=5.3.3",
        ....
        "trt/resque-bundle": "~1.0",
        ...
    },

Add the AsyncTasksBundle to your application's kernel:

public function registerBundles()
{
    $bundles = array(
        ...
        new Trt\AsyncTasksBundle\TrtAsyncTasksBundle(),
        ...
    );
    ...
}

Configuration

trt_async_tasks:
    # This prefix allows the dispatcher to detect async event,
    # if you want use another prefix put here ↙
    event:
        prefix: async_
    mq:
        # The rabbitMq host / port ↙
        connection_params:
            host: %mq_host%
            port: %mq_port%
        # Define the exchange name for rabbitmq ↙
        exchange:
            exchange: 'exchange_symfony_events'

Naming Conventions

AsyncTasksBundle's event detection mechanism is based on naming convention, the event name will be the same of queue name. every event with name containing the async string will be detected as AysncEvent.

The name prefix cold be overridden via config

trt_async_tasks:
    event:
        prefix: acme_async

This bundle will be shown at SymfonyDayIt 2013 (Rome)

Fork it and contribute to solve the issues :-)

License

See: resources/meta/LICENSE.md

Credits

The bundle structure and the documentation is partially based on the SonataNotificationBundle

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.