How to Work Laravel Event, Jobs, Listeners and Queue-Different Among Event, Jobs, Listeners and Queue and Programming with them

  1. Event: A thing that happens or takes place
  2. Job: A task or piece of work
  3. Queue: A list of data items, commands, etc., stored so as to be retrievable in a definite order

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.