Queues as we know follow the First In/First Out terminology. This means that whoever is first in the queue is meant to be taken care of first. They are generally run in the background via consoles/shells.
What are these queues connections?
Therefore, database/storage engines that store the entries for processing the queues are required. Nowadays, people generally use redis (site) or sqs (a service given by Amazon Web Services) as one of these databases/storage engines.
In Laravel, we have queue drivers which store the necessary details (like the hostname, the port number, username, password) to connect to these databases/storage engines.
What onQueue method does?
OnQueue
method is defined inside the Queueable
trait (\Illuminate\Bus\Queueable.php) which is used to specify the queue on which a particular job/event has to to be pushed to.
Basically, when you go config/queue.php
, you'll find a connections array. Something like...
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'expire' => 60,
],
The second last element of the it is queue
which is used for naming the queue of that particular connection. By using different queue names, you can parallelize your jobs/events and run them on different queue connections for faster processing.
So, one queue can be used to send mails, and the other for maybe... checking something in your database and then storing the data into cache based on the output.
Also, before you ask anymore questions, I'd suggest you to try this out yourself. You can start out with redis and install it in your local machine. Once you're through with that, you can start it by the redis-server
command and then in your laravel project run things from your queue by php artisan queue:listen
command.