Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel difference between Events, Listeners, Jobs, Queues [closed]

Tags:

It sounds extremely confusing to me, what are the differences? Can someone please do an ELI5?

like image 439
Taylor Avatar asked Mar 19 '16 20:03

Taylor


1 Answers

Although they all can work together, I find it's easiest to look at Events and Listeners together, and then Jobs and Queues together.

Events and Listeners

Events are objects that hold data that are "fired", the Laravel event system "catches" the event object when it is fired, and then all the Listeners that are registered for that particular event are run.

If you think about it, this is akin to how exceptions work. You throw an exception, and you can define several catch blocks to react depending on which exception is thrown. In the case of Events and Listeners, an Event is thrown and one or more Listeners represent the contents of a catch block. Though similar, Events and Listeners are not error handlers, they just have conceptual similarities.

Jobs and Queues

I think the best way to think of these is like a line at a bank. The line itself is the Queue, and each customer in the line is a Job.

In order to process Jobs in the Queue you need command line processes or daemons. Think of launching a queue daemon on the command line as adding a new bank teller to the pool of available bank tellers. When a daemon is available it will ask the Queue for the next Job like the bank teller asking for the next person in line to step to the window.

Each person in line has a specific task they want accomplished, like making a deposit or withdrawal. The action that the person in line needs completed is the Worker in Laravel.

The Worker is the thing the daemon will do for the Job that was taken from the Queue, just like the task is the thing the bank teller will do for the customer who stepped forward from the line.

Hope any of that makes some sense.

like image 163
stratedge Avatar answered Sep 18 '22 08:09

stratedge