For installation please use docker as the following:
docker pull rabbitmq:3-management
docker run --rm -it -p 15672:15672 -p 5672:5672 rabbitmq:3-management
Congrats!!!
composer require vladimir-yuldashev/laravel-queue-rabbitmq
//change the queue connection type to
QUEUE_CONNECTION=rabbitmq
//Add the following
RABBITMQ_HOST=127.0.0.1
RABBITMQ_PORT=5672
RABBITMQ_USER=guest
RABBITMQ_PASSWORD=guest
RABBITMQ_VHOST=/
'connections' => [
...,
'rabbitmq' => [
'driver' => 'rabbitmq',
'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', '/'),
'queue' => env('RABBITMQ_QUEUE', 'default'),
]
],
],
],
php artisan make:job <job_name>
class <job_name> implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private $data;
/**
* Create a new job instance.
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Execute the job.
*/
public function handle(): void
{
}
}
class <job_name> implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private $data;
/**
* Create a new job instance.
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Execute the job.
*/
public function handle(): void
{
Log::info('hi there from consumer');
$order = Order::find($this->data['id']);
$order->email_sent = true;
$order->save();
}
}
OrderCreated::*dispatch*($order->toArray());