jurry / laravel-rabbitmq
RabbitMQ for Laravel & Lumen Frameworks
1.2
2021-05-01 10:33 UTC
Requires
- ext-sockets: *
- guzzlehttp/guzzle: *
- illuminate/console: *
- illuminate/validation: *
- php-amqplib/php-amqplib: ^2.11
- symfony/console: ^5.0
This package is auto-updated.
Last update: 2024-12-25 12:44:39 UTC
README
Description:
Its purpose is to initiate workers (consumers) and to send "sync" and "async" requests to another queues or exchanges.
Installation
composer require jurry/laravel-rabbitmq
Usage
-
Register this package into your AppServiceProvider:
class AppServiceProvider { public function register() { ... $this->app->singleton(\Jurry\RabbitMQ\Handler\AmqpHandler::class, function () { return new \Jurry\RabbitMQ\Handler\AmqpHandler( env('JURRY_RABBITMQ_HOST'), // host env('JURRY_RABBITMQ_PORT'), // port env('JURRY_RABBITMQ_USERNAME'), // username env('JURRY_RABBITMQ_PASSWORD'), // password '\App\Services', // classesNamespace, where the consumer will look for to process the message with targeted service class [ 'sync_queue' => [ // Sync queue options, will be used when declare the queue 'name' => 'stores_sync', 'message_ttl' => 10000, ], 'async_queue' => [ // Async queue options, will be used when declare the queue 'name' => 'stores_async', 'message_ttl' => 10000, ], ] ); }); } }
- You can change the parameters as wish you need
-
Register your custom command by adding your created class to the $commands member inside the app/Console/Kernel.php file:
class Kernel extends ConsoleKernel { /** * The Artisan commands provided by your application. * * @var array */ protected $commands = [ // ... \Jurry\RabbitMQ\Command\SyncConsumerCommand::class, \Jurry\RabbitMQ\Command\AsyncConsumerCommand::class, ]; // ... }
-
Start new workers:
php artisan amqp:sync_worker php artisan amqp:async_worker