Get the App
SLTechnology News&Howtos  ›  Development  › 

How laravel uses RabbitMQ

Shulou Source: shulou.com Published: 2022-06-02 05:15:46 10月02日 Update

This article mainly introduces "how laravel uses RabbitMQ". In daily operation, I believe many people have doubts about how to use RabbitMQ in laravel. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how laravel uses RabbitMQ". Next, please follow the editor to study!

Homestead (ubuntu) + Laravel use RabbitMQ usage 1: use laravel-queue-rabbitmq alone

Laravel installation RabbitMQ:

First of all, pay attention to the laravel version information supported by your laravel-queue-rabbitmq:

Package VersionLaravel VersionBug Fixes Until

96October 5th, 2021Documentation106, 7October 5th, 2021Documentation118April 6th, 2021Documentation

Execute the installation command:

Composer require vladimir-yuldashev/laravel-queue-rabbitmq

Wait for the installation to complete and add to config/queue.php:

'connections' = > [/ /... 'rabbitmq' = > [' driver' = > 'rabbitmq',' queue' = > env ('RABBITMQ_QUEUE',' default'), 'connection' = > PhpAmqpLib\ Connection\ AMQPLazyConnection::class,' hosts' = > ['host' = > env (' RABBITMQ_HOST', '127.0.0.1'), 'port' = > env (' RABBITMQ_PORT', 5672) 'user' = > env (' RABBITMQ_USER', 'guest'),' password' = > env ('RABBITMQ_PASSWORD',' guest'), 'vhost' = > env (' RABBITMQ_VHOST','/'),], 'options' = > [' ssl_options' = > ['cafile' = > env (' RABBITMQ_SSL_CAFILE', null) 'local_cert' = > env (' RABBITMQ_SSL_LOCALCERT', null), 'local_key' = > env (' RABBITMQ_SSL_LOCALKEY', null), 'verify_peer' = > env (' RABBITMQ_SSL_VERIFY_PEER', true), 'passphrase' = > env (' RABBITMQ_SSL_PASSPHRASE', null),] 'queue' = > [' job' = > VladimirYuldashev\ LaravelQueueRabbitMQ\ Queue\ Jobs\ RabbitMQJob::class,],], / * * Set to "horizon" if you wish to use Laravel Horizon. * / 'worker' = > env (' RABBITMQ_WORKER', 'default'),], / /...]

And modify it in config/queue.php:

/ / change sync to rabbitmq, and use redis driver to change to redis'default' = > env ('QUEUE_CONNECTION',' sync'), 'default' = > env (' QUEUE_CONNECTION', 'rabbitmq'), or modify QUEUE_CONNECTION=rabbitmqQUEUE_CONNECTION=rabbitmq under .env

Execute the command to generate the task class:

Php artisan make:job TestQueue

Modify the TestQueue.php code:

Tags: Queues that is accounts passwords methods permissions learning consumption management background commands data methods more consumers producers languages questions help support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi OPPO Reno vpn Redmi MySQL