Queued event handlers in laravel 5.1

 

If we would like to not have the event handled immediately, but rather, put into the queue, we can add –queued to the create command as follows:

$ php artisan handler:eventdateReservedEmail --event=dateWasReserved --queued
    <?php namespace MyCompanyHandlersEvents;
    
    use MyCompanyEventsdateWasReserved;
    
    use IlluminateQueueInteractsWithQueue;
    use IlluminateContractsQueueShouldBeQueued;
    
    class RoomReservedEvent implements ShouldBeQueued {
    
    use InteractsWithQueue;
    
    public function __construct()
    {
        //
    }
    
    use IlluminateContractsQueueShouldBeQueued;

This interface tells Laravel that the event handler should be queued and not executed synchronously:

use IlluminateQueueInteractsWithQueue;

This trait allows us to interact with the queue to be able to do tasks, such as delete the job.

If we would like to not have the event handled immediately, but rather, put into the queue, we can add –queued to the create command as follows:

$ php artisan handler:eventdateReservedEmail --event=dateWasReserved --queued
    <?php namespace MyCompanyHandlersEvents;
    
    use MyCompanyEventsdateWasReserved;
    
    use IlluminateQueueInteractsWithQueue;
    use IlluminateContractsQueueShouldBeQueued;
    
    class RoomReservedEvent implements ShouldBeQueued {
    
    use InteractsWithQueue;
    
    public function __construct()
    {
        //
    }
    
    use IlluminateContractsQueueShouldBeQueued;

This interface tells Laravel that the event handler should be queued and not executed synchronously:

use IlluminateQueueInteractsWithQueue;

This trait allows us to interact with the queue to be able to do tasks, such as delete the job.

Deven Rathore

Deven is an Entrepreneur, and Full-stack developer, Constantly learning and experiencing new things. He currently runs CodeSource.io and Dunebook.com.

Published by
Deven Rathore

Recent Posts

3 Ways to Get the Most Out of Your University’s Virtual Computer Lab

IT is more important than ever in the world of higher education, and yet with…

21 hours ago

Top Tips for Learning Java Programming

If you’re here for the top tips, we assume you’re ahead of the “how to…

1 day ago

Neural Networks for Creating Blog Texts

The world is progressing at unprecedented rates at the current moment, especially in terms of…

2 days ago

Top 20 Opensource Python Tkinter Projects

This article will highlight the Top 20 Opensource Python Tkinter Projects which we believe will…

4 days ago

Beginners guide to Sneaker Proxies

With their numerous applications in streamlining the data flow, securing both the servers and the…

1 week ago

Top 20 Node.js dashboard templates

In this article, We will be looking at some of the top Node.js dashboard templates.…

1 week ago