2017 © Pedro Peláez
 

library tail

RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple

image

foolkaka/tail

RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple

  • Friday, October 27, 2017
  • by foolkaka
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 22 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

foolkaka/tail

RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple., (*1)

Build Status Latest Stable Version License, (*2)

Features

  • Simple queue configuration
  • Multiple server connections
  • Add message to queues easily
  • Listen queues with useful options

Requirements

  • php-amqplib/php-amqplib: 2.*

Version

1.0.6, (*3)

Installation

Preparation, (*4)

Open your composer.json file and add the following to the require array:, (*5)

"foolkaka/tail": "1.*"

Install dependencies, (*6)

$ composer install

Or, (*7)

$ composer update

Integration

Laravel

After installing the package, open your Laravel config file config/app.php and add the following lines., (*8)

In the $providers array add the following service provider for this package., (*9)

Foolkaka\Tail\ServiceProvider::class,

In the $aliases array add the following facade for this package., (*10)

'Tail' => Foolkaka\Tail\Facades\Tail::class,

Add servers connection file running:, (*11)

$ php artisan vendor:publish --provider="Foolkaka\Tail\ServiceProvider" --tag="config"

Lumen

Register the Lumen Service Provider in bootstrap/app.php:, (*12)

/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
*/

//...

$app->configure('tail-settings');
$app->register(Foolkaka\Tail\LumenServiceProvider::class);

//...

Make sure sure $app->withFacades(); is uncomment in your bootstrap/app.php file, (*13)

Create a config folder in the root directory of your Lumen application and copy the content from vendor/foolkaka/tail/config/tail.php to config/tail-settings.php., (*14)

RabbitMQ Connections

By default the library will use the RabbitMQ installation credentials (on a fresh installation the user "guest" is created with password "guest")., (*15)

To override the default connection or add more servers, edit the RabbitMQ connections file at: config/tail-settings.php, (*16)

return array(

    'default' => 'default_connection',

    'connections' => array(

        'default_connection' => array(
            'host'         => 'localhost',
            'port'         => 5672,
            'username'     => 'guest',
            'password'     => 'guest',
            'vhost'        => '/',
            'exchange'     => 'default_exchange_name',
            'consumer_tag' => 'consumer',
            'exchange_type'=> 'direct',
            'content_type' => 'text/plain',
            'ssl_connect'  => false,
            'ssl_options'  => [
                'cafile' => '/opt/certs/ca.cert.pem',
                'local_cert' => '/opt/certs/local_cert.pem',
                'verify_peer' => true,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            ]
        ),    
        'other_server' => array(
            'host'         => '192.168.0.10',
            'port'         => 5672,
            'username'     => 'guest',
            'password'     => 'guest',
            'vhost'        => '/',
            'exchange'     => 'default_exchange_name',
            'consumer_tag' => 'consumer',
            'exchange_type'=> 'fanout',
            'content_type' => 'application/json',
            'ssl_connect'  => false,
            'ssl_options'  => [
                'cafile' => '/opt/certs/ca.cert.pem',
                'local_cert' => '/opt/certs/local_cert.pem',
                'verify_peer' => true,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            ]
        ),
    ),
);

Adding messages to queue:

Adding a simple message, (*17)

    Tail::add('queue-name', 'message');

Adding message changing RabbitMQ server, (*18)

    Tail::add('queue-name', 'message', array('connection_name' => 'connection_name_config_file'));

Adding message with different exchange, (*19)

    Tail::add('queue-name', 'message', array('exchange' => 'exchange_name'));

Adding message with different content type, (*20)

    Tail::add('queue-name', '{ 'message' : 'message' }', array('content_type' => 'application/json'));

Adding message with different options, (*21)

    $options = array (
        'connection_name' => 'connection_name_config_file',
        'exchange' => 'exchange_name',
        'vhost' => 'vhost'
    );  

    Tail::add('queue-name', 'message', $options);

Using Tail object, (*22)

    $message = new Tail::createMessage;
    $message->queue_name = 'queue-name';
    $message->message = 'message';
    $message->connection_name = 'connection_name_in_config_file';
    $message->exchange = 'exchange_name';
    $message->vhost = 'vhost';
    $message->content_type = 'content/type'

    $message->save();

Listening queues:

Closure based listener, (*23)

Tail::listen('queue-name', function ($message) {

    //Your message logic code
});

Closure listener with options, (*24)

$options = array(
    'message_limit' => 50,
    'time' => 60,
    'empty_queue_timeout' => 5,
    'connection_name' => 'connection_name_in_config_file',
    'exchange' => 'exchange_name',
    'vhost' => 'vhost'
);

Tail::listenWithOptions('queue-name', $options, function ($message) {

    //Your message logic code       
});

Options definitions:, (*25)

Name Description Default value
queue_name Queue name on RabbitMQ * Required
message_limit Number of messages to be processed 0: Unlimited
time Time in seconds the process will be running 0: Unlimited
empty_queue_timeout Time in seconds to kill listening when the queue is empty 0: Unlimited
connection_name Server connection name Defined at connections file
exchange Exchange name on RabbitMQ Server Specified on connections file
vhost Virtual host on RabbitMQ Server Specified on connections file

By default the listen process will be running forever unless you specify one of the running time arguments above (message_limit, time, empty_queue_timeout). They can be mixed all together, so when one of the condition is met the process will be stopped., (*26)

License

This package is open-sourced software licensed under the MIT license, (*27)

The Versions

27/10 2017

dev-master

9999999-dev

RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Victor Cruz

laravel rabbitmq library queue client laravel5 package victor cruz foolkaka

27/10 2017

dev-dev

dev-dev

RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Victor Cruz

laravel rabbitmq library queue client laravel5 package victor cruz foolkaka

27/10 2017

v1.0.6

1.0.6.0

RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Victor Cruz

laravel rabbitmq library queue client laravel5 package victor cruz foolkaka

30/07 2016

v1.0.5

1.0.5.0

RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Victor Cruz

laravel rabbitmq library queue client laravel5 package victor cruz mookofe

30/07 2016

dev-release/1.0.5

dev-release/1.0.5

RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Victor Cruz

laravel rabbitmq library queue client laravel5 package victor cruz mookofe

26/04 2016

v1.0.4

1.0.4.0

RabbitMQ and PHP client for Laravel that allows you to add and listen queues messages just simple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Victor Cruz

laravel rabbitmq queue client laravel5 package victor cruz mookofe

17/07 2015

v1.0.3

1.0.3.0

RabbitMQ and PHP client for Laravel that allows you to add and listen queues messages just simple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Victor Cruz

laravel rabbitmq queue client laravel5 package victor cruz mookofe

07/07 2015

v1.0.2

1.0.2.0

RabbitMQ and PHP client that allows you to add and listen queues messages just simple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Victor Cruz

laravel rabbitmq queue client laravel5 package victor cruz mookofe

06/07 2015

v1.0.1

1.0.1.0

RabbitMQ and PHP client that allows you to add and listen queues messages just simple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Victor Cruz

laravel framework rabbitmq queue laravel5 victor cruz mookofe

06/07 2015

v1.0.0

1.0.0.0

RabbitMQ and PHP client that allows you to add and listen queues messages just simple

  Sources   Download

MIT

The Requires

 

The Development Requires

by Victor Cruz

laravel framework rabbitmq queue laravel5 victor cruz mookofe