dougua9328 2016-12-25 10:14
浏览 1702
已采纳

什么是Laravel队列连接和onQueue方法? [关闭]

I just finished to read laravel documentation about queues and I dont understand somethings.

  1. What are these queues connections ?
    What they do?
    What is the difference between 'beanstalkd' , 'sqs', 'iron' and 'redis' ?

  2. What onQueue method does?
    I read that you can with named queues tou can categorize the workers, but what the workers are? jon classes?
    For what it's good?

  • 写回答

1条回答 默认 最新

  • doudg60800 2016-12-25 11:23
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?