Coder Social home page Coder Social logo

slmqueueamq's Introduction

SlmQueueAmq

Build Status PHP 7 ready Code Coverage Latest Stable Version Latest Unstable Version Scrutinizer Code Quality Dependency Status

Created by Jurian Sluiman

Requirements

Installation

First, install SlmQueue (instructions here). Then, add the following line into your composer.json file:

"require": {
    "slm/queue-amq": "0.4.*"
}

Then, enable the module by adding SlmQueueAmq in your application.config.php file. You may also want to configure the module: just copy the slm_queue_amq.local.php.dist (you can find this file in the config folder of SlmQueueAmq) into your config/autoload folder, and override what you want.

Documentation

Before reading SlmQueueAmq documentation, please read SlmQueue documentation.

(Don't forget to first install Active MQ, and to run the daemon program on the server)

Setting the connection parameters

Copy the slm_queue_amq.local.php.dist file to your config/autoload folder, and follow the instructions.

Adding queues

A concrete class that implements the SlmQueue interface for Active MQ is included as SlmQueueAmq\Queue\AmqQueue and a factory is available to create the queue. Therefore, if you want to have a queue called "email", just add the following line in your module.config.php file:

return array(
    'slm_queue' => array(
        'queue_manager' => array(
            'factories' => array(
                'email' => 'SlmQueueAmq\Factory\AmqQueueFactory'
            )
        )
    )
);

This queue can therefore be pulled from the QueuePluginManager class.

Operations on queues

push

Valid options are all constants on the SlmQueueAmq\Queue\AmqQueueInterface interface:

  • AmqQueueInterface::DELAY: the delay in milliseconds before a job become available to be popped (defaults to no delay)
  • AmqQueueInterface::PERIOD: in milliseconds, how much time a job can be running for before it's put back into the queue
  • AmqQueueInterface::REPEAT: the number of times the job should be repeatedly available (defaults to 1, no repeating jobs)
  • AmqQueueInterface::CRON: a CRON string to schedule the job via cron
  • AmqQueueInterface::PERSIST: set to true to send a persistent message

Example:

use SlmQueueAmq\Queue\AmqQueueInterface as Amq;

$queue->push($job, array(
    Amq::CRON     => '0 * * * *',
    Amq::DELAY    => 1000,
    Amq::PERIOD   => 1000,
    Amq::REPEAT   => 9
));

The above code will deliver the job 10 times, with a one second delay between each job, and this will happen every hour. See more explaination about the options in the Active MQ manual.

pop

Valid option is:

  • timeout: by default, when we ask for a job, it will block until a job is found (possibly forever if new jobs never come). If you set a timeout (in seconds), it will return after the timeout is expired, even if no jobs were found

Executing jobs

SlmQueueAmq provides a command-line tool that can be used to pop and execute jobs. You can type the following command within the public folder of your Zend Framework 2 application:

php index.php queue amq <queue> [--timeout=]

The queue is a mandatory parameter, while the timeout is an optional flag that specifies the duration in seconds for which the call will wait for a job to arrive in the queue before returning (because the script can wait forever if no job come).

slmqueueamq's People

Watchers

James Cloos avatar 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.