2017 © Pedro Peláez
 

library burrow

AMQP Messaging Event component

image

evaneos/burrow

AMQP Messaging Event component

  • Friday, April 6, 2018
  • by oliviermadre
  • Repository
  • 16 Watchers
  • 3 Stars
  • 21,924 Installations
  • PHP
  • 4 Dependents
  • 1 Suggesters
  • 2 Forks
  • 3 Open issues
  • 27 Versions
  • 22 % Grown

The README.md

Burrow

Build Status Scrutinizer Code Quality Packagist Version Code Coverage, (*1)

Evaneos AMQP library able to use both php-amqplib and pecl amqp C librairy, (*2)

Installation

composer require evaneos/burrow

Usage

See examples directory for more details
To test it, you may use a rabbitmq container, this one feets perfectly, (*3)

docker run -d -p 5672:5672 rabbitmq

Declare an exchange and bind a queue with RabbitMQ

$admin = DriverFactory::getDriver([
    'host' => 'localhost',
    'port' => '5672',
    'user' => 'guest',
    'pwd' => 'guest'
]);
$admin->declareExchange('exchange');
$admin->declareAndBindQueue('exchange', 'my_queue');

Asynchronous management

Dispatching an async message with RabbitMQ

$driver = DriverFactory::getDriver([
    'host' => 'localhost',
    'port' => '5672',
    'user' => 'guest',
    'pwd' => 'guest'
]);
$publisher = new AsyncPublisher($driver, 'exchange');
$publisher->publish('message', 'routing_key', [ 'meta' => 'data' ]);

Write a daemon to consume async messages from RabbitMQ

$driver = DriverFactory::getDriver([
    'host' => 'default',
    'port' => '5672',
    'user' => 'guest',
    'pwd' => 'guest'
]);
$handlerBuilder = new HandlerBuilder($driver);
$handler = $handlerBuilder->async()->build(new EchoConsumer());
$daemon = new QueueHandlingDaemon($driver, $handler, 'test');
$worker = new Worker($daemon);
$worker->run();

In the command-line, launch both scripts from a different terminal, the message 'my_message', should be displayed in the worker terminal., (*4)

Synchronous management

Dispatching an async message with RabbitMQ

$driver = DriverFactory::getDriver([
   'host' => 'default',
   'port' => '5672',
   'user' => 'guest',
   'pwd' => 'guest'
]);
$publisher = new SyncPublisher($driver, 'xchange');
$publisher->publish('my_message', 'routing_key', [ 'meta' => 'data' ]);

Write a daemon to consume async messages from RabbitMQ

$driver = DriverFactory::getDriver([
   'host' => 'default',
   'port' => '5672',
   'user' => 'guest',
   'pwd' => 'guest'
]);

$handlerBuilder = new HandlerBuilder($driver);
$handler = $handlerBuilder->sync()->build(new ReturnConsumer());
$daemon = new QueueHandlingDaemon($driver, $handler, 'test');
$worker = new Worker($daemon);
$worker->run();

In the command-line, launch both scripts from a different terminal, the message 'my_message', should be displayed in the publisher terminal., (*5)

Events

You can add your emitter to subscribe events: - DaemonStart - DaemonStopped - MessageReceived - MessageConsumed, (*6)

$emitter = new League\Event\Emitter();
$emitter->addListener(new MyListener());

new QueueHandlingDaemon([..], $emitter);

Metrics

Based on events, you can subscribe a built-in metric publisher which will send this metrics: - daemon.started (increment) - daemon.stopped (increment) - daemon.message_received (increment) - daemon.message_consumed (increment) - daemon.message_processing_time (timing), (*7)

There is an implementation for StatsD and DogStatsD., (*8)

$config = ['host' => 'host', 'port' => 'port'];

// StatsD
$metricService = MetricServiceFactory::create('statsd', $config);
// DogStatsD
$tags = ['service' => 'myService']; // This tags will be sent with all the metrics
$metricService = MetricServiceFactory::create('dogstats', $config, $tags);

$emitter = new League\Event\Emitter();
$emitter->useListenerProvider(new SendMetricListenerProvider($metricService));

new QueueHandlingDaemon([..], $emitter);

Examples

All these examples are also available in the example directory., (*9)

Handlers

You can now use handlers to modify the consumption behaviour. For retro-compatibility reasons, a ContinueOnFailureHandler has been created to reproduce the previous default behaviour. Please, do not use it anymore as it is quite dangerous to allow the worker to continue when receiving an error., (*10)

To ease the use of the handlers, please build the handler stack using HandlerBuilder., (*11)

The Versions

15/04 2016
07/04 2016
12/03 2016
01/03 2016
02/12 2015

dev-swarrot

dev-swarrot

AMQP Messaging Event component

  Sources   Download

MIT

The Requires

 

The Development Requires

07/10 2015

2.2.0

2.2.0.0

AMQP Messaging Event component

  Sources   Download

MIT

The Requires

 

The Development Requires

06/10 2015

2.1.0

2.1.0.0

AMQP Messaging Event component

  Sources   Download

MIT

The Requires

 

The Development Requires

06/07 2015

v2.0.2

2.0.2.0

AMQP Messaging Event component

  Sources   Download

MIT

The Requires

 

The Development Requires

20/05 2015

v2.0.1

2.0.1.0

AMQP Messaging Event component

  Sources   Download

MIT

The Requires

 

The Development Requires

13/05 2015

v2.0.0

2.0.0.0

AMQP Messaging Event component

  Sources   Download

MIT

The Requires

 

The Development Requires

24/04 2015

v1.1.0

1.1.0.0

AMQP Messaging Event component

  Sources   Download

MIT

The Requires

 

The Development Requires

03/04 2015

dev-remove-useless-condition

dev-remove-useless-condition

AMQP Messaging Event component

  Sources   Download

MIT

The Requires

 

The Development Requires

04/03 2015

v1.0.3

1.0.3.0

AMQP Messaging Event component

  Sources   Download

MIT

The Requires

 

The Development Requires

24/02 2015

v1.0.2

1.0.2.0

AMQP Messaging Event component

  Sources   Download

MIT

The Requires

 

The Development Requires

23/02 2015

v1.0.1

1.0.1.0

AMQP Messaging Event component

  Sources   Download

MIT

The Requires

 

The Development Requires

19/01 2015

v1.0.0

1.0.0.0

AMQP Messaging Event component

  Sources   Download

MIT

The Requires

 

The Development Requires