Marketplace-Dependencies / rabbitmq-for-laravel by wajdijurry

RabbitMQ for Laravel & Lumen Frameworks
79
0
0
Package Data
Maintainer Username: wajdijurry
Maintainer Contact: jurrywajdi@yahoo.com (Wajdi Jurry)
Package Create Date: 2021-05-01
Package Last Update: 2023-10-25
Language: PHP
License: MIT
Last Refreshed: 2024-04-14 15:01:00
Package Statistics
Total Downloads: 79
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 0
Total Forks: 0
Total Open Issues: 0

RabbitMQ Package for Laravel & Lumen Frameworks

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

  1. 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
  2. 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,
        ];
    
        // ...
    
    }
    
    
  3. Start new workers:

    php artisan amqp:sync_worker
    php artisan amqp:async_worker