mercredi 21 septembre 2016

Laravel 5.2 Queuing events

I have some events that perform CRUD, uploads, and emails. I would like to queue these events. I did some research and found that all I need to do is configure my queue driver and implement ShouldQueue contract in my event listeners. Since I'm using redis as my Cache and session driver, I went ahead and used redis as my queue driver. When I fire my events without using ShouldQueue, everything works fine, I get emails, data gets added to DB ..etc. But when I add ShouldQueue to my event listeners and I run queue:listen I fire my events but nothing gets added or executed in the queue. I also don't get any emails, DB ...etc. What am I missing? Here is an example of my code:

.env file

QUEUE_DRIVER=redis

App\Events\ContactUs\CustomerContactUs

use SerializesModels;
/**
 * Create a new event instance.
 */
public function __construct()
{

}

App\Listeners\ContactedUs\SendCustomerEmailToUs

private $mailer;
private $request;    
public function __construct(Mailer $mailer, Request $request)
{
    $this->mailer = $mailer;
    $this->request = $request;
}
public function handle(CustomerContactedBullard $event)
{
....   
$this->mailer->send('public.emails.contact_us',$this->request->all(),$params);
}

ContactUsController

event(new ContactedUs\CustomerContactedUs());

Terminal I run

php artisan queue:listen

Thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire