2017 © Pedro Peláez
 

library swarrot

A simple lib to consume RabbitMQ queues

image

swarrot/swarrot

A simple lib to consume RabbitMQ queues

  • Saturday, June 9, 2018
  • by Stof
  • Repository
  • 19 Watchers
  • 289 Stars
  • 347,888 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 47 Forks
  • 7 Open issues
  • 40 Versions
  • 12 % Grown

The README.md

Swarrot

Build Status Scrutinizer Quality Score Latest Stable Version Latest Unstable Version, (*1)

Swarrot is a PHP library to consume messages from any broker., (*2)

Installation

The recommended way to install Swarrot is through Composer. Require the swarrot/swarrot package:, (*3)

$ composer require swarrot/swarrot

Usage

Basic usage

First, you need to create a message provider to retrieve messages from your broker. For example, with a PeclPackageMessageProvider (retrieves messages from an AMQP broker with the pecl amqp package:, (*4)

use Swarrot\Broker\MessageProvider\PeclPackageMessageProvider;

// Create connection
$connection = new \AMQPConnection();
$connection->connect();
$channel = new \AMQPChannel($connection);
// Get the queue to consume
$queue = new \AMQPQueue($channel);
$queue->setName('global');

$messageProvider = new PeclPackageMessageProvider($queue);

Once it's done you need to create a Processor to process messages retrieved from the broker. This processor must implement Swarrot\Processor\ProcessorInterface. For example:, (*5)

use Swarrot\Processor\ProcessorInterface;
use Swarrot\Broker\Message;

class Processor implements ProcessorInterface
{
    public function process(Message $message, array $options): bool
    {
        echo sprintf("Consume message #%d\n", $message->getId());

        return true; // Continue processing other messages
    }
}

You now have a Swarrot\Broker\MessageProviderInterface to retrieve messages and a Processor to process them. So, ask the Swarrot\Consumer to do its job :, (*6)

use Swarrot\Consumer;

$consumer = new Consumer($messageProvider, $processor);
$consumer->consume();

Using a stack

Heavily inspired by stackphp/builder you can use Swarrot\Processor\Stack\Builder to stack your processors. Using the built in processors or by creating your own, you can extend the behavior of your base processor. In this example, your processor is decorated by 2 other processors. The ExceptionCatcherProcessor which decorates your own with a try/catch block and the MaxMessagesProcessor which stops your worker when some messages have been consumed., (*7)

use Swarrot\Processor\ProcessorInterface;
use Swarrot\Broker\Message;

class Processor implements ProcessorInterface
{
    public function process(Message $message, array $options): bool
    {
        echo sprintf("Consume message #%d\n", $message->getId());

        return true; // Continue processing other messages
    }
}

$stack = (new \Swarrot\Processor\Stack\Builder())
    ->push('Swarrot\Processor\MaxMessages\MaxMessagesProcessor', new Logger())
    ->push('Swarrot\Processor\ExceptionCatcher\ExceptionCatcherProcessor')
    ->push('Swarrot\Processor\Ack\AckProcessor', $messageProvider)
;

$processor = $stack->resolve(new Processor());

Here is an illustration to show you what happens when this order is used:, (*8)

this, (*9)

Processors

Official processors

Create your own processor

To create your own processor and be able to use it with the StackProcessor, you just need to implement ProcessorInterface and to take another ProcessorInterface as first argument in constructor., (*10)

Deprecated processors & message providers / publishers

In order to reduce swarrot/swarrot dependencies & ease the maintenance, some processors & message providers / publishers have been deprecated in 3.x version. They will be deleted in 4.0., (*11)

If you use those deprecated classes you could create your own repository to keep them or we could create a dedicated repository under the swarrot organisation if you're willing to help to maintain them., (*12)

Message providers / publishers

  • SQS Message provider (in 3.5.0)
  • Stomp message providers (in 3.6.0)
  • Stomp message publishers (in 3.7.0)
  • Interop message publishers & providers (in 3.7.0)

Processors

  • SentryProcessor (in 3.5.0)
  • RPC related processors (in 3.5.0)
  • NewRelicProcessor (in 3.7.0)

Inspiration

License

Swarrot is released under the MIT License. See the bundled LICENSE file for details., (*13)

The Versions

20/07 2017

v3.0.0

3.0.0.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

queue worker amqp swarrot

26/06 2017

v2.4.0

2.4.0.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

queue worker amqp swarrot

20/06 2017

dev-release-2-4

dev-release-2-4

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

queue worker amqp swarrot

20/06 2017

dev-php7-1

dev-php7-1

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

queue worker amqp swarrot

28/12 2016

v2.3.0

2.3.0.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

queue worker amqp swarrot

15/06 2016

v2.2.0

2.2.0.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

27/12 2015

v2.1.2

2.1.2.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

03/06 2015
03/06 2015
18/04 2015
24/02 2015
06/01 2015
27/11 2014
01/11 2014
25/10 2014

v1.4.0

1.4.0.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

17/07 2014

v1.3.0

1.3.0.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

16/07 2014

v1.2.8

1.2.8.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

15/07 2014

v1.2.7

1.2.7.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

03/07 2014

v1.2.6

1.2.6.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

02/07 2014

v1.2.5

1.2.5.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

27/06 2014

v1.2.4

1.2.4.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

19/06 2014

v1.2.3

1.2.3.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

16/06 2014

v1.2.2

1.2.2.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

13/05 2014

v1.2.1

1.2.1.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

23/04 2014

v1.2.0

1.2.0.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

02/04 2014

v1.1.4

1.1.4.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

01/04 2014

v1.1.3

1.1.3.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

01/04 2014

v1.1.2

1.1.2.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

01/04 2014

v1.1.1

1.1.1.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

01/04 2014

v1.1.0

1.1.0.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot

25/03 2014

v1.0.0

1.0.0.0

A simple lib to consume RabbitMQ queues

  Sources   Download

MIT

The Requires

 

The Development Requires

worker swarrot