The Laravel queue service provides a unified API across a variety of different queue back-ends. Queues allow you to defer the processing of a time consuming task, such as sending an e-mail, until a later time which drastically speeds up web requests to your application.
php artisan make:job Queue
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class Queue implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
protected $data;
public function __construct($data)
{
$this->data = $data;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
//用作处理消息队列内的数据
echo json_encode($this->data);
}
}
install rabbitmq
安装完直接访问http://localhost:15672/ 账号密码都是guest/guest
using
download laravel5.5
Install this package via composer using:
Add these properties to .env with proper values:
Other AMQP transports
producer
consumer
listen queue
参考链接