Coder Social home page Coder Social logo

slmqueue's Introduction

SlmQueue

Build Status Code Coverage Latest Stable Version Latest Unstable Version Dependency Status

Created by Jurian Sluiman and Michaël Gallego

Introduction

SlmQueue is a job queue abstraction layer for Zend Framework 2 applications. It supports various job queue systems and makes your application independent from the underlying system you use. The currently supported systems have each their own adapter-module and are the following:

A job queue helps to offload long or memory-intensive processes from the HTTP requests clients sent to the Zend Framework 2 application. This will make your response times shorter and your visitors happier. There are many use cases for asynchronous jobs and a few examples are:

  1. Send an email
  2. Create a PDF file
  3. Connect to a third party server over HTTP

In all cases you want to serve the response as soon as possible to your visitor, without letting them wait for this long process. SlmQueue enables you to implement a job queue system very easily within your existing application.

Installation

SlmQueue works with Composer. Make sure you have the composer.phar downloaded and you have a composer.json file at the root of your project. To install it, add the following line into your composer.json file:

"require": {
    "slm/queue": "^1.0"
}

After installation of the package, you need to complete the following steps to use SlmQueue:

  1. Enable the module by adding SlmQueue in your application.config.php file.
  2. Copy the slm_queue.global.php.dist (you can find this file in the config folder of SlmQueue) into your config/autoload folder and apply any setting you want.

NB. SlmQueue is a skeleton and therefore useless by itself. Enable an adapter to give you the implementation details you need to push jobs into the queue. Choose one of the available adapters SlmQueueBeanstalkd, SlmQueueSqs or SlmQueueDoctrine

Requirements

Code samples

Below are a few snippets which show the power of SlmQueue in your application. The full documentation is available in docs/ directory.

A sample job to send an email with php's mail() might look like this:

namespace MyModule\Job;

use SlmQueue\Job\AbstractJob;

class EmailJob extends AbstractJob
{
    public function execute()
    {
        $payload = $this->getContent();

        $to      = $payload['to'];
        $subject = $payload['subject'];
        $message = $payload['message'];

        mail($to, $subject, $message);
    }
}

If you want to inject this job into a queue, you can do this for instance in your controller:

Since v0.8.0 you can also add additional options (in the example the job will be delay by a minute)

namespace MyModule\Controller;

use MyModule\Job\Email as EmailJob;
use SlmQueue\Queue\QueueInterface;
use Zend\Mvc\Controller\AbstractActionController;

class MyController extends AbstractActionController
{
    protected $queue;

    public function __construct(QueueInterface $queue)
    {
        $this->queue = $queue;
    }

    public function fooAction()
    {
        // Do some work

        $job = new EmailJob;
        $job->setContent(array(
            'to'      => '[email protected]',
            'subject' => 'Just hi',
            'message' => 'Hi, I want to say hi!'
        ));

        $this->queue->push($job, ['delay' => 60]);
    }
}

Now the above code lets you insert jobs in a queue, but then you need to spin up a worker which can process these jobs. Giving an example with beanstalkd and a queue which you called "default", you can start a worker with this command:

php public/index.php queue beanstalkd default

Contributing

SlmQueue is developed by various fanatic Zend Framework 2 users. The code is written to be as generic as possible for Zend Framework 2 applications. If you want to contribute to SlmQueue, fork this repository and start hacking!

Any bugs can be reported as an issue at GitHub. If you want to contribute, please be aware of the following guidelines:

  1. Fork the project to your own repository
  2. Use branches to work on your own part
  3. Create a Pull Request at the canonical SlmQueue repository
  4. Make sure to cover changes with the right amount of unit tests
  5. If you add a new feature, please work on some documentation as well

For long-term contributors, push access to this repository is granted.

slmqueue's People

Contributors

bakura10 avatar basz avatar malinink avatar eddiejaoude avatar garygitton avatar kokx avatar bnitobzh avatar dronchik avatar dkmuir avatar frankhouweling avatar fgruntjes avatar jackdpeterson avatar michaelthessel avatar robertmarsal avatar svycka avatar sasezaki avatar

Watchers

Prakash A 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.