PHP code example of jurry / laravel-rabbitmq

1. Go to this page and download the library: Download jurry/laravel-rabbitmq library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jurry / laravel-rabbitmq example snippets


    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,
                        ],
                    ]
                );
            });
        }
    }
    

    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,
        ];
    
        // ...
    
    }
    
    
bash
    php artisan amqp:sync_worker
    php artisan amqp:async_worker