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

WowoQueueBundle

by wowo

The WowoQueueBundle provides unified method for use queue systems, like Beanstalkd, RabbitMQ, flat files, database driven queues etc.

WowoQueueBundle

Build Status
SensioLabsInsight

The WowoQueueBundle provides unified method for use queue systems, like Beanstalkd, RabbitMQ, flat files,
database driven queues, etc. For now it only supports Beanstalkd, but you can add your own implementation
on your own and send pull request.

Installation

Step 1: Download WowoQueueBundle

If you are using Deps (Symfony 2.0.x)

Add following lines to your deps file:

    [WowoQueueBundle]
        git=git://github.com/wowo/WowoQueueBundle.git
        target=bundles/Wowo/QueueBundle

    [pheanstalk]
        git=https://github.com/pda/pheanstalk
        target=/pheanstalk
        version=v2.1.0

Now, run the vendors script to download the bundle:

$ php bin/vendors install

If you are using Composer (Symfony >= 2.1.x)

Add following lines to your composer.json requirements:

    "require": {
        "wowo/wowo-queue-bundle": "dev-master"
    }

Now, install the bundle with composer:

$ php composer.phar install

Step 2: Configure the Autoloader

(You can jump to Step 3 if you are using composer)

Add the Wowo namespace to your autoloader:

<?php
// app/autoload.php

$loader->registerNamespaces(array(
    // ...
        'Wowo' => __DIR__.'/../vendor/bundles',
        ));

Also add Pheanstalk init on the bottom of autoload:

// ...
require_once __DIR__.'/../vendor/pheanstalk/pheanstalk_init.php';

Step 3: Enable the bundle

Finally, enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
        $bundles = array(
            // ...
            new Wowo\QueueBundle\WowoQueueBundle(),
        );
}

Step 4: install and run beanstalkd

On Debian linux systems (including Ubuntu) you can run:

$ sudo apt-get install beanstalkd

Then run it as a daemon:

$ beanstalkd -d -l 127.0.0.1 -p 11300

Note: If your beanstalkd service is running in other address or port, you must set the following parameter in your configuration:

parameters:
    wowo_queue.default.address: 127.0.0.1:11300

Don't forget to change 127.0.0.1:11300 with your address and port.

Usage

Using Beanstalkd in-memory queueing server

Obtain manager with Beanstalkd implementation from the controller

$manager = $this->get('wowo_queue.manager');

Put some job into the queue to default tube wowo_queue. which can be changed by wowo_queue.pheanstalk.tube parameter

$manager->put(json_encode(array('payload' => 'Hello world', 'date' => new \DateTime())));

Get jobs as soon as they appear in queue. In below example an infinite loop is presented.
Such operations should be run as a background tasks, which listens to the queue and processes jobs when they appear.

while ($job = $manager->get()) {
    $data = json_decode($job->getData(), true);
    printf("Job date: %s, payload: %s\n", $data['date']['date'], $data['payload']);
}

Deleting jobs from the queue is fairly easy

$job = $manager->get();
$manager->delete($job);

Using Beanstalkd implementation without service container

Manager object creation is simple and can be done as listed below.
This is useful when you don't use bundle in Symfony project.

$implementation = new Wowo\QueueBundle\Implementation\BeanstalkdQueueImplementation();
$implementation->configure(array(
    'address' => 'localhost',
    'tube' => 'foo-tube',
));
$manager = new Wowo\QueueBundle\QueueManager($implementation);

In case you are not using autoloader, Pheanstalk need to be autoloaded by hand:

require_once('pheanstalk/classes/pheanstalk/classloader.php');
\pheanstalk_classloader::register('pheanstalk/classes/');

tracking

Amazon SQS

The SQSQueueImplementation utilizes the AWS PHP SDK v2

Configuration

To inject the SQS Implementation into your QueueManager, make sure you instantiate it with a
configured SQS client and an associative array mapping tube names to SQS queue names.

Symfony bundle's services.yml example

# general AWS SQS client
queue.sqs_client:
class: Aws\Sqs\SqsClient
factory_class: Aws\Sqs\SqsClient
factory_method: factory
arguments:
- {credentials: {key: %amazon.s3.key%, secret: %amazon.s3.secret%}, region: %amazon.s3.region%}
# wowo sqs implementation
queue.implementation.sqs:
class: Wowo\QueueBundle\Implementation\SQSQueueImplementation
arguments: [@queue.sqs_client, %queue.tubes_to_sqs%]

From there, you can simply inject the SQS implementation into your QueueManager to get or put messages

wowo_queue:           []
  • Merge pull request #22 from StanleyGibbons/putBatch
    By wowo, 4 years ago
  • Remove SqsClient type hinting and switch to mockery.
    By aheinz-sg, 4 years ago
  • Coding standards.
    By aheinz-sg, 4 years ago
  • Merge pull request #23 from wowo/feature/travis-update
    By wowo, 4 years ago
  • Code cleanup
    By wowo, 4 years ago
  • Updated travis config to deprecated 5.3 and add new versions
    By wowo, 4 years ago
  • Reimplement putBatch with SQS-specific sendMessageBatch.
    By aheinz-sg, 4 years ago
  • Initial implementation of putBatch as looping call to put.
    By aheinz-sg, 4 years ago
  • Merge pull request #21 from pere605/master
    By wowo, 5 years ago
  • fixed failing build
    By Piotr Leśniowski, 5 years ago
  • Merge pull request #19 from fousheezy/master
    By wowo, 5 years ago
  • Merge pull request #20 from pere605/master
    By wowo, 5 years ago
  • added possibility to define ttr
    By Piotr Leśniowski, 5 years ago
  • Updating for style conformity
    By , 5 years ago
  • Adding SQS queue implementation.
    By foush, 5 years ago
  • Merge pull request #18 from mrosiu/changed-access-to-constants-method
    By wowo, 5 years ago
  • changed method to access for constants
    By Mateusz Rosiek, 5 years ago
  • Merge pull request #17 from mimol91/master
    By wowo, 6 years ago
  • fix typo
    By Adam Szaraniec, 6 years ago
  • Added SensioLabsInsight Badge to README
    By wowo, 6 years ago
  • Merge branch 'master' of github.com:wowo/WowoQueueBundle
    By Wojciech Sznapka, 6 years ago
  • Fixed violations reported by SensioLabsInsight
    By Wojciech Sznapka, 6 years ago
  • Merge pull request #16 from phansys/master
    By wowo, 7 years ago
  • Resolved local conflict.
    By phansys, 7 years ago
  • Updated README.markdown according config updates (https://github.com/wowo/WowoQueueBundle/blob/64b1b9f64c42ea3428f376be49d07d1f61e1c9ba/Resources/config/services.xml#L24, https://github.com/wowo/WowoQueueBundle/commit/64b1b9f64c42ea3428f376be49d07d1f61e1c
    By phansys, 7 years ago
  • Merge pull request #15 from mrosiu/seperate-resource-management-method
    By wowo, 7 years ago
  • moved the code responsible for management of external resources into a seperate method
    By Mateusz Rosiek, 7 years ago
  • Merge pull request #14 from wojciech-olszewski/readme-fix
    By wowo, 7 years ago
  • fix pheanstalk version in deps installation
    By Wojciech Olszewski, 7 years ago
  • Added coveralls config
    By Wojciech Sznapka, 7 years ago