为什么BroadCastEvent在Laravel排队?如何阻止这种情况?
2022-08-30 19:50:01
我正在从事需要实时广播纬度和经度的项目
我有如下内容
namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Support\Facades\Redis;
class TrackersBroadcast extends Event implements ShouldBroadcast
{
public $lat, $lng,$imei,$date_time
use SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(
$lat,
$lng,
$imei,
$date_time
)
{
$this->lat = $lat;
$this->lng = $lng;
$this->imei = $imei;
$this->date_time = $date_time;
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return ['tracker-channel'];
}
}
在某些情况下,我需要触发实时电子邮件,所以我决定实现如下的laravel消息队列
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Mail;
class SendAlertEmail extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
public $data;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($data)
{
$this->data=$data;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
Mail::send('emails.test', ['testVar' => $this->data], function($message) {
$message->from('no-reply@sample.com', 'Website Name');
$message->to('developer@gmail.com')->subject('A simple test');
});
}
}
每当我运行它也会将我的广播事件排队。我不想对广播事件进行排队。如何做到这一点?php artisan queue:listen database