initx/querabilis

Simple PHP Queue

0.6 2019-06-10 16:11 UTC

This package is auto-updated.

Last update: 2020-01-28 20:19:15 UTC


README

Compliant with JAVA Queue interface

Build Status Code Coverage

Installation

$ composer require initx/querabilis

Usage

Driver

use Initx\Querabilis\Driver\FilesystemQueue;

$queue = new FilesystemQueue('./queue');

Push to queue

use Initx\Querabilis\Envelope;

$envelope = new Envelope('Payload goes here');

$queue->add($envelope);

Pull form queue

$envelope = $queue->remove();

$envelope->getPayload(); // "Payload goes here"

Currently supported drivers

  • Amazon SQS
  • Redis (Predis)
  • AMQP
  • Beanstalkd
  • Filesystem
  • In memory

Each driver implements Queue interface.

Summary of Queue interface

Insert
  • add(e) - inserts an element if possible, otherwise throwing exception
  • offer(e) - inserts an element if possible, otherwise returning false
Remove
  • remove() - remove and return head of queue, otherwise throwing exception
  • poll() - remove and return head of queue, otherwise returning null
Examine
  • element() - return but do not remove head of queue, otherwise throwing exception
  • peek() - return but do not remove head of queue, otherwise returning null

More examples

Redis (Predis) driver
use Predis\Client;
use Initx\Querabilis\Driver\RedisQueue;

$client = new Client(['host' => '127.0.0.1']);
$queue = new RedisQueue($client, 'queueName');
AWS SQS driver
use Aws\Sqs\SqsClient;
use Initx\Querabilis\Driver\SqsQueue;

$client = new SqsClient(your_sqs_client_config);
$queue = new SqsQueue($client, 'queueName');
In memory driver
use Initx\Querabilis\Driver\InMemoryQueue;

$queue = new InMemoryQueue();
Beanstalkd driver
use Pheanstalk\Pheanstalk;
use Initx\Querabilis\Driver\BeanstalkdQueue;

$client = Pheanstalk::create([your_beanstalkd_config]);
$queue = new BeanstalkdQueue($client);
AMQP driver
use PhpAmqpLib\Connection\AMQPStreamConnection;
use Initx\Querabilis\Driver\AmqpQueue;

$connection = new AMQPStreamConnection([your_amqp_config]);
$queue = new AmqpQueue($connection, 'queueName', 'exchange');