dev-master
9999999-devBernard bindings for Laravel
MIT
The Requires
The Development Requires
by Ulrich Kautz
laravel queue worker serviceprovider bernard service-provider
Bernard bindings for Laravel
Brings Bernard to Laravel. Laravel already has a great queue.. That's right, but it only works with Laravel. If your project/company utilizes multiple frameworks, Bernard provides leverage., (*2)
Extend composer.json
file:, (*3)
``` json { "require": { "bernard/laravel": "@dev" } }, (*4)
Register the service provider in `app/config/app.php`: ``` php <?php // ... 'providers' => array( // .. 'Bernard\Laravel\BernardServiceProvider' // .. )
Now you need to choose the Driver you want to use. Initialize the default config file with artisan
:, (*5)
``` bash $ php artisan config:publish bernard/laravel, (*6)
This creates the file `app/config/packages/bernard/laravel/config.php`. ### Redis Config in `app/config/packages/bernard/laravel/config.php` ``` php <?php return array( 'driver' => 'predis', );
Setup predis
in IoC:, (*7)
``` php <?php, (*8)
App::singleton('predis', function () { return new \Predis\Client(null, array( 'prefix' => 'bernard:' )); });, (*9)
Requires the `predis/predis` composer package. ### SQS Config in `app/config/packages/bernard/laravel/config.php` ``` php <?php return array( 'driver' => 'sqs', // optional: use prefetching for efficiency //'prefetch' => 10, // optional: pre-set queue name -> url mappings //'queue_urls' => array('some-queue' => 'https://sqs.eu-west-1.amazonaws.com/123123/some-queue', ...) );
Setup sqs
in IoC:, (*10)
``` php <?php, (*11)
use Aws\Sqs\SqsClient;, (*12)
// ..., (*13)
App::singleton('sqs', function () { return SqsClient::factory(array( 'key' => 'Your AWS Access Key', 'secret' => 'Your AWS Secret Key', 'region' => 'Your AWS Region' )); });, (*14)
Requires the `aws/aws-sdk-php` composer package. ### Iron MQ Config in `app/config/packages/bernard/laravel/config.php` ``` php <?php return array( 'driver' => 'iron_mq', // use prefetching for efficiency //'prefetch' => 10 );
Setup iron_mq
in IoC:, (*15)
``` php <?php, (*16)
App::singleton('iron_mq', function () { return new \IronMq(array( 'token' => 'Your IronMQ Token', 'project_id' => 'Your IronMQ Project ID', )); });, (*17)
### Eloquent For small projects or testing. Config in `app/config/packages/bernard/laravel/config.php` ``` php <?php return array( 'driver' => 'eloquent', );
You also need to migrate the required tables (once):, (*18)
``` bash $ php artisan migrate --package=bernard/laravel, (*19)
Usage ----- ### In Laravel without Facades In your Laravel app, add a new message to the queue: ``` php <?php $this->app['bernard:producer']->produce(new \Bernard\Message\DefaultMessage('MyService', array( 'my' => 'args', )));
Add the two aliases in your app/config/app.php
config file like so:, (*20)
``` php <?php, (*21)
return array( // .. 'aliases' => array( // .. 'Producer' => 'Bernard\Laravel\Facades\Producer', 'Consumer' => 'Bernard\Laravel\Facades\Consumer', ), );, (*22)
And now you can use them as any other Facade in Laravel: ``` php <?php Producer::message('MyService', array('my' => 'args'));
``` bash, (*23)
$ php artisan bernard:produce MyService '{"json":"data"}', (*24)
$ php artisan bernard:consume my-service ```, (*25)
Bernard bindings for Laravel
MIT
laravel queue worker serviceprovider bernard service-provider